Accessing sequence browser proxy node in python for screen recording

Hi,

I am trying to use Python to generate screen-recorded videos of actions in Slicer. I am trying to do so by initializing a sequence browser and recording the main 3D view of ‘Camera’ in Python. I can do it manually, but would like to do it all programmatically.

I am stuck on how to set the main 3D-view camera to be the proxy node for the sequence browser.

Here is what I have so far:

# create a new sequence browser node
newSequenceBrowserNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSequenceBrowserNode', 'MySBN')
# create a new sequence node
newSequenceNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSequenceNode', 'Seq1')
# pair the sequence browser node and the sequence node
newSequenceBrowserNode.SetAndObserveMasterSequenceNodeID(newSequenceNode.GetID())
# enable recording
newSequenceBrowserNode.SetRecording(newSequenceNode,True)
*** [somehow set the proxy node] ***
# start recording
newSequenceBrowserNode.RecordingActiveOn()
# perform operations that will be recorded
...
# stop recording
newSequenceBrowserNode.RecordingActiveOff()
# use screen capture module to save as video
...

I am able to get the cameraNode, but am unable to set it as the proxy node from which information will be recorded.

layoutManager  = slicer.app.layoutManager()
view           = layoutManager.threeDWidget(0).threeDView()
threeDViewNode = view.mrmlViewNode()
cameraNode     = slicer.modules.cameras.logic().GetViewActiveCameraNode(threeDViewNode)

Any help will be greatly appreciated!

The SlicerAnimator code probably has what you need.

Thanks, I’ll take a look and follow up if any questions come up

Hi,

Just following up on this thread. I have a working version of code that records actions in the 3D view using the sequence browser and then outputs them to a video using the screen capture module. The ‘proxy node’ that gets recorded is ‘Default Scene Camera’.

All motions are logged in the sequence browser, but changes in color are not. More specifically, I change the color of the segmentation object every 10 seconds, but only the final color gets captured in the video. I can capture just the color change if I set the ‘proxy node’ to the segmentation object.

Is it possible to follow two nodes (i.e. the scene camera and the object color) so that I can record both the color changes and the camera motions simultaneously?

Thanks