# Error with maskvolumewithsegment with python

**URL:** https://discourse.slicer.org/t/error-with-maskvolumewithsegment-with-python/12169
**Category:** Support
**Created:** [June 23, 2020, 4:26am UTC](https://discourse.slicer.org/t/error-with-maskvolumewithsegment-with-python/12169 "2020-06-23T04:26:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![stl](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@stl](https://discourse.slicer.org/u/stl)
#### Post date: [June 23, 2020, 4:26am UTC](https://discourse.slicer.org/t/error-with-maskvolumewithsegment-with-python/12169/1 "2020-06-23T04:26:13Z")

</div>

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](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!

---

<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: [June 26, 2020, 1:03pm UTC](https://discourse.slicer.org/t/error-with-maskvolumewithsegment-with-python/12169/2 "2020-06-26T13:03:34Z")

</div>

As you can see [here](https://github.com/lassoan/SlicerSegmentEditorExtraEffects/blob/d28b9218342f57cc04ba1d5a61f50628a5884500/SegmentEditorMaskVolume/SegmentEditorMaskVolumeLib/SegmentEditorEffect.py#L339-L342), `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?

---

<div class="post-metadata">

### Author: ![stl](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@stl](https://discourse.slicer.org/u/stl)
#### Post date: [June 26, 2020, 7:19pm UTC](https://discourse.slicer.org/t/error-with-maskvolumewithsegment-with-python/12169/3 "2020-06-26T19:19:11Z")

</div>

Thank you!

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

Thanks again.
