# Fill between slices by code

**URL:** <https://discourse.slicer.org/t/fill-between-slices-by-code/13586>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [September 21, 2020, 2:23pm UTC](https://discourse.slicer.org/t/fill-between-slices-by-code/13586 "2020-09-21T14:23:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luigi-palladino](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/luigi-palladino/32/8323_2.png) [@luigi-palladino](https://discourse.slicer.org/u/luigi-palladino)\
**Post date:** [September 21, 2020, 2:23pm UTC](https://discourse.slicer.org/t/fill-between-slices-by-code/13586/1 "2020-09-21T14:23:50Z")

</div>

Hi,

I would like to perform the effect “Fill between slices” of the Segment Editor in my application on a Segment Node that I have.  
I can’t figure out how to do that by code. Is there a way to do that?

I’m in Slicer 4.11.0-2019-09-25

Thank you for your help.

---

<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:** [September 21, 2020, 2:43pm UTC](https://discourse.slicer.org/t/fill-between-slices-by-code/13586/2 "2020-09-21T14:43:19Z")

</div>

See examples here: [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How\_to\_run\_segment\_editor\_effects\_from\_a\_script](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script)

“Fill between slices” effect works the same way as “Grow from seeds” effect, so the “[brain tumor segmentation using grow from seeds effect](https://gist.github.com/lassoan/2d5a5b73645f65a5eb6f8d5f97abf31b)” example should work as is, you just need to change the effect name.

---

<div class="post-metadata">

**Author:** ![luigi-palladino](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/luigi-palladino/32/8323_2.png) [@luigi-palladino](https://discourse.slicer.org/u/luigi-palladino)\
**Post date:** [September 21, 2020, 3:15pm UTC](https://discourse.slicer.org/t/fill-between-slices-by-code/13586/3 "2020-09-21T15:15:01Z")

</div>

Thank you very much, editing this piece of code from your link worked.

```
# Run filter
################################################

# Create segment editor to get access to effects
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
# To show segment editor widget (useful for debugging): segmentEditorWidget.show()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(masterVolumeNode)

# Run segmentation
segmentEditorWidget.setActiveEffectByName("Fill between slices")
effect = segmentEditorWidget.activeEffect()
# You can change parameters by calling: effect.setParameter("MyParameterName", someValue)
# Most effect don't have onPreview, you can just call onApply
effect.self().onPreview()
effect.self().onApply()
```
