# Issue Applying Wrap Solidify in Python Script

**URL:** <https://discourse.slicer.org/t/issue-applying-wrap-solidify-in-python-script/41742>\
**Category:** Development\
**Tags:** segmentation, python, 3d-model\
**Created:** [February 17, 2025, 2:37pm UTC](https://discourse.slicer.org/t/issue-applying-wrap-solidify-in-python-script/41742 "2025-02-17T14:37:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miri\_Trope](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/miri_trope/32/67690_2.png) [@Miri\_Trope](https://discourse.slicer.org/u/Miri_Trope)\
**Post date:** [February 17, 2025, 2:37pm UTC](https://discourse.slicer.org/t/issue-applying-wrap-solidify-in-python-script/41742/1 "2025-02-17T14:37:40Z")

</div>

Dear community,

I’m trying to apply **Wrap Solidify** in a Python script following the instructions provided [here](https://lassoan.github.io/SlicerSegmentationRecipes/SkinSurface2/). I’ve attached the code:

> # Create a segmentation node
> 
> segmentationNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentationNode”)  
> segmentationNode.CreateDefaultDisplayNodes()  
> segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
> 
> # Create segment editor
> 
> segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()  
> segmentEditorWidget.setMRMLScene(slicer.mrmlScene)  
> segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentEditorNode”)  
> segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)

> # Configure segment editor for thresholding
> 
> segmentEditorWidget.setSegmentationNode(segmentationNode)  
> segmentEditorWidget.setSourceVolumeNode(masterVolumeNode)
> 
> # Apply Threshold Effect
> 
> segmentEditorWidget.setActiveEffectByName(“Threshold”)  
> effect = segmentEditorWidget.activeEffect()  
> effect.setParameter(“MinimumThreshold”, 30)  
> effect.setParameter(“MaximumThreshold”, 800)  
> effect.self().onApply()  
> print(“Threshold effect applied successfully.”)
> 
> # Apply Islands Effect
> 
> segmentEditorWidget.setActiveEffectByName(“Islands”)  
> effect = segmentEditorWidget.activeEffect()  
> effect.setParameter(“MinimumSize”, 1000) # Minimum size in mm³ for islands to keep (adjust as needed)  
> effect.setParameter(“MaxIslandCount”, 0) # Set to 0 to remove all islands smaller than the size threshold  
> effect.self().onApply()  
> print(“Islands effect applied successfully.”)
> 
> # Apply Wrap Solidify Effect
> 
> segmentEditorWidget.setActiveEffectByName(“Wrap Solidify”)  
> effect = segmentEditorWidget.activeEffect()  
> effect.setParameter(“OuterSurface”, True)  
> effect.setParameter(“CarveHoles”, True)  
> effect.setParameter(“SmoothingFactor”, 25) # Corrected parameter  
> effect.self().onApply()  
> print(“Wrap Solidify effect applied successfully.”)

However, I’m encountering the following error:

> Traceback (most recent call last):  
> File “/Applications/Slicer.app/Contents/Extensions-33216/SurfaceWrapSolidify/lib/Slicer-5.8/qt-scripted-modules/SegmentEditorWrapSolidifyLib/SegmentEditorEffect.py”, line 252, in onApply  
> self.logic.applyWrapSolidify()  
> File “/Applications/Slicer.app/Contents/Extensions-33216/SurfaceWrapSolidify/lib/Slicer-5.8/qt-scripted-modules/SegmentEditorWrapSolidifyLib/SegmentEditorEffect.py”, line 338, in applyWrapSolidify  
> regionPd = self.\_getInitialRegionPd()  
> File “/Applications/Slicer.app/Contents/Extensions-33216/SurfaceWrapSolidify/lib/Slicer-5.8/qt-scripted-modules/SegmentEditorWrapSolidifyLib/SegmentEditorEffect.py”, line 526, in \_getInitialRegionPd  
> raise ValueError(“Region segment cannot be the same segment as the current segment”)  
> ValueError: Region segment cannot be the same segment as the current segment

Does anyone have suggestions on how to resolve it?

---

<div class="post-metadata">

**Author:** ![Miri\_Trope](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/miri_trope/32/67690_2.png) [@Miri\_Trope](https://discourse.slicer.org/u/Miri_Trope)\
**Post date:** [May 27, 2025, 12:41pm UTC](https://discourse.slicer.org/t/issue-applying-wrap-solidify-in-python-script/41742/2 "2025-05-27T12:41:07Z")

</div>

Hi again, I found the cause of the error: it seems WrapSolidify needs a separate region segment from the one being wrapped. I was using the same segment, which triggered the `ValueError: Region segment cannot be the same segment as the current segment`.

I’d appreciate a working Python snippet that demonstrates how to properly define and assign the region segment programmatically (e.g., using `effect.setParameter(RegionSegmentID)`). Is there a recommended way to set this parameter reliably from code?

Thank you!
