AttributeError: type object 'vtkSlicerSegmentationsModuleMRMLPython.vtkMRMLSegm' has no attribute 'PaintAllowedEverywhere'

I am creating a script to run iteratively over subfolders with baboon skull CTs in DICOM format.

In the pipeline, I need to do a segmentation of the full skulls via Thresholding (which works nice in the script) and and Removing small islands (which is not).

This is part of the code with the segmentation part:

    # SEGMENTATION
    # Start the segmentation subroutine (threshold + island tools + smoothing and morphological closing)
    # https://gist.github.com/lassoan/1673b25d8e7913cbc245b4f09ed853f9
    
    # Create segmentation
    segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
    segmentationNode.CreateDefaultDisplayNodes() # only needed for display
    segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(croppedVolume)
    addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment(baboon_skull)
    
    # Create segment editor to get access to effects
    segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
    segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
    segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentEditorNode")
    segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
    segmentEditorWidget.setSegmentationNode(segmentationNode) # (yourOutputSegmentation)
    segmentEditorWidget.setMasterVolumeNode(croppedVolume)    # (yourVolume)
    
    # Segmentation: Thresholding
    segmentEditorWidget.setActiveEffectByName("Threshold")
    effect = segmentEditorWidget.activeEffect()
    effect.setParameter("MinimumThreshold","60")
    effect.setParameter("MaximumThreshold","3071")
    effect.self().onApply()

    # Segmentation: Systematically remove small islands
    # https://discourse.slicer.org/t/islands-segmentation-via-python-script/21021
    segmentEditorNode.SetSelectedSegmentID("baboon_skull")
    segmentEditorWidget.setActiveEffectByName("Islands")
    effect = segmentEditorWidget.activeEffect()
    effect.setParameter("MinimumSize","1000")
    effect.setParameter("Operation","KEEP_LARGEST_ISLAND")
    segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteNone) 
    segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedEverywhere)  
    effect.self().onApply()

My Python console returns an error in the before last line:

segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedEverywhere)

This is the error that I get:

Traceback (most recent call last):
  File "<string>", line 84, in <module>
AttributeError: type object 'vtkSlicerSegmentationsModuleMRMLPython.vtkMRMLSegm' has no attribute 'PaintAllowedEverywhere'

I don’t know where the problem might be. Any idea?

I followed @rbumm script that was inserted in another Slicer question (link in the code)

I solved the problem by commenting three extra lines:

# Segmentation: Systematically remove small islands
# https://discourse.slicer.org/t/islands-segmentation-via-python-script/21021
# segmentEditorNode.SetSelectedSegmentID("baboon_skull")
segmentEditorWidget.setActiveEffectByName("Islands")
effect = segmentEditorWidget.activeEffect()
# effect.setParameter("MinimumSize","1000")
# effect.setParameter("Operation","KEEP_LARGEST_ISLAND")
segmentEditorNode.SetOverwriteMode(slicer.vtkMRMLSegmentEditorNode.OverwriteNone) 
segmentEditorNode.SetMaskMode(slicer.vtkMRMLSegmentEditorNode.PaintAllowedEverywhere)  
effect.self().onApply()