Automate setting source volume and geometry in Segment Editor


When I open the segment editor module, I’d like the source volume and geometry to automatically be set to a specific volume which I have loaded into the display view. Is it possible to automate this in my code?

To display the desired node I used :

lm =
redCompositeNode = lm.sliceWidget('Red').mrmlSliceCompositeNode() 

Thank you

You should be able to adapt the following:

mw = slicer.util.mainWindow()
modulePanel = findChild(mw, "ModulePanel")

def onModuleEntered(moduleName):
    if moduleName != "SegmentEditor":
    print(f"Entered {moduleName}")
    # Get reference to the volume loaded a background
    sliceNode = slicer.util.getNode("vtkMRMLSliceNodeRed")
    sliceLogic =
    sourceVolume = sliceLogic.GetBackgroundLayer().GetVolumeNode()
    # Get reference to the vtkMRMLSegmentEditorNode used in the segment editor module
    # This node is storing parameters associated with the segment editor widget (qMRMLSegmentEditorWidget)
    segmentEditorNode = slicer.modules.SegmentEditorWidget.parameterSetNode


Adding this to the Slicer Application startup file would ensure it always happen.