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

**URL:** <https://discourse.slicer.org/t/how-to-change-the-masking-setting-of-the-segmenteditor-by-python/23380>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [May 12, 2022, 2:03am UTC](https://discourse.slicer.org/t/how-to-change-the-masking-setting-of-the-segmenteditor-by-python/23380 "2022-05-12T02:03:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xing\_Lu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xing_lu/32/15282_2.png) [@Xing\_Lu](https://discourse.slicer.org/u/Xing_Lu)\
**Post date:** [May 12, 2022, 2:03am UTC](https://discourse.slicer.org/t/how-to-change-the-masking-setting-of-the-segmenteditor-by-python/23380/1 "2022-05-12T02:03:29Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/3/53ef0aee5bb31956e6d7ec524a0432a704de58ae.png)  
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!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 12, 2022, 2:08am UTC](https://discourse.slicer.org/t/how-to-change-the-masking-setting-of-the-segmenteditor-by-python/23380/2 "2022-05-12T02:08:04Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![Xing\_Lu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xing_lu/32/15282_2.png) [@Xing\_Lu](https://discourse.slicer.org/u/Xing_Lu)\
**Post date:** [May 30, 2022, 11:46pm UTC](https://discourse.slicer.org/t/how-to-change-the-masking-setting-of-the-segmenteditor-by-python/23380/3 "2022-05-30T23:46:50Z")

</div>

That really helps, Andras!

It is solved, thanks! Sorry for my late reply.
