Error with maskvolumewithsegment with python

Hi,

Slicer 4.10.2 , Windows

I’ve been trying to access the mask volume effect with python and keep running into the following problem:

This is the relevant code for segment labeled “Tumor”:

segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(masterVolumeNode)

segmentEditorWidget.setActiveEffectByName(“Mask volume”)
effect = segmentEditorWidget.activeEffect()
maskedVolume = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLScalarVolumeNode”, “masked volume”)
effect.self().maskVolumeWithSegment(segmentationNode,“Tumor”,“FILL_OUTSIDE”,-1,masterVolumeNode,maskedVolume)

This is the error I get:

Traceback (most recent call last):
File “”, line 1, in
File “C:/Users/Neeraja/AppData/Roaming/NA-MIC/Extensions-28257/SegmentEditorExtraEffects/lib/Slicer-4.10/qt-scripted-modules/SegmentEditorMaskVolumeLib/SegmentEditorEffect.py”, line 400, in maskVolumeWithSegment
stencil.SetBackgroundValue(fillValues[0])
TypeError: ‘int’ object has no attribute ‘getitem

I’ve checked each of the inputs for maskVolumeWithSegment and reviewed the source code(https://github.com/lassoan/SlicerSegmentEditorExtraEffects/blob/master/SegmentEditorMaskVolume/SegmentEditorMaskVolumeLib/SegmentEditorEffect.py#L400) but can’t seem to figure out what is wrong.

If I switch to “FILL_INSIDE” the error shifts to Line 390 but is otherwise the same.

I would appreciate any suggestions/ideas.

Thank you!

As you can see here, maskVolumeWithSegment method now expects a list of one or two values. Where did you find the example code snippet that still used a number instead of a list?

Thank you!

I used the same linked script but did not see that it had to be a list.

Thanks again.