How to change the masking setting of the segmenteditor by python?

image
trying to change this ‘Overwrite other segmentation’ option programmably. However, I tried the code:

defaultSegmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
defaultSegmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteVisibleSegments)
slicer.mrmlScene.AddDefaultNode(defaultSegmentEditorNode)

But it doesn’t work actually, everytime the default is still shown as ‘Allsegments’.

Any suggestions?

Thanks so much!

This changes the default. It does not affect the current setting if you have already switched to the Segment Editor before or you loaded a scene that contained a segment editor node.

You can change the masking settings in all the existing segment editor nodes like this:

for segmentEditorNode in slicer.util.getNodesByClass('vtkMRMLSegmentEditorNode'):
  segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteVisibleSegments)