Modify Wrap Solidify values with Python

Hi! I have a question regarding accessing the Wrap Solidify extension through scripting - in a certain step it uses predefined values to perform a wrapping on the active segment. (I’m using Slicer version 5.8.1)

Background: I have tried many different approaches in the coding, but I couldn’t find a way to modify the slider values through the Python console. I attach a basic script below to show how it was given to the console.

The issue: What I have found, that even though the parameters were given directly, the execution still uses those values which are shown in the UI window of the wrap solidify.

The question: what should be modified to be able to change the individual floating value parameters?

Thank you for your help!

segmentEditorWidget.setActiveEffectByName("Wrap Solidify")
effect = segmentEditorWidget.activeEffect()

if not effect:
    raise RuntimeError("❌ Wrap Solidify effect not found!")

effect.setParameter("region", "largestCavity")
effect.setParameter("splitCavities", True)
effect.setParameter("splitCavitiesDiameterMm", 2.0)  
effect.setParameter("smoothingFactor", 0.3)       
effect.setParameter("oversamplingFactor", 1.0)    
effect.setParameter("numberOfIterations", 1)     
effect.setParameter("outputType", "newSegment")      
effect.setParameter("saveIntermediateResults", False)

effect.self().onApply()

print("Wrap Solidify applied with predefined parameters.")
slicer.app.processEvents()


Pass strings to setParameter, ex str(1).

Dear @chir.set,

Thank you for the quick response! I have tried it (script attached), but the program still uses those values written in the UI boxes and not the one given via the Python script.

What is your suggestion?

segmentEditorWidget.setActiveEffectByName("Wrap Solidify")
effect = segmentEditorWidget.activeEffect()

if not effect:
    raise RuntimeError("❌ Wrap Solidify effect not found!")

effect.setParameter("region", "largestCavity")
effect.setParameter("splitCavities", True)
effect.setParameter("splitCavitiesDiameterMm", str(2.0))  
effect.setParameter("smoothingFactor", str(0.3))       
effect.setParameter("oversamplingFactor", str(1.0))    
effect.setParameter("numberOfIterations", str(1))     
effect.setParameter("outputType", "newSegment")      
effect.setParameter("saveIntermediateResults", False)

effect.self().onApply()

print("Wrap Solidify applied with predefined parameters.")
slicer.app.processEvents()

You can poke the right parameter names in SegmentEditorWrapSolidifyLib/SegmentEditorEffect.py.

For example, splitCavitiesDiameterMm should have been splitCavitiesDiameter.

@chir.set: Thank you very much! I’ve checked the source, revised it accordingly, and now it works fine!

I paste below the updated script for those who has similar issues that they could see the corrected version:

segmentEditorWidget.setActiveEffectByName("Wrap Solidify")
effect = segmentEditorWidget.activeEffect()

effect.setParameter("region", "largestCavity")
effect.setParameter("splitCavities", str(True))
effect.setParameter("splitCavitiesDiameter", str(2.0))
effect.setParameter("smoothingFactor", str(0.3))
effect.setParameter("remeshOversampling", str(1.0))
effect.setParameter("shrinkwrapIterations", str(1))
effect.setParameter("outputType", "newSegment")
effect.setParameter("saveIntermediateResults", str(False))

effect.self().onApply()

print("Wrap Solidify applied with corrected parameters.")
slicer.app.processEvents()