Draw tube scripting

Hi all,

I am trying to automate the “Draw Tube” effect in Segment Editor using Python, but I am stuck at two points:

  1. How to pass an existing centerline to the effect programmatically (similar to setting "Radius" or "Interpolation" via setParameter()).

  2. How to trigger the “Import” button automatically via code after setting the parameters.

Here is what I have so far:

segmentEditorWidget = slicer.modules.segmenteditor.widgetRepresentation().self().editor
segmentEditorWidget.setActiveEffectByName("Draw tube")
effect = segmentEditorWidget.activeEffect()

effect.setParameter("Radius", 0.3)
effect.setParameter("Interpolation", "CARDINAL_SPLINE")  # or "LINEAR"

I want to fully automate the workflow: use an existing MarkupsCurveNode as the centerline, generate the tube segment, and “import” it, without any manual interaction.

Could someone please advise:

  • What is the correct parameter name for passing a centerline to the Draw Tube effect?

  • How can I simulate clicking the Import button programmatically in Python?

  • Why does setting "Interpolation" update the GUI but "Radius" does not, and how should I set the radius properly so the interface updates as well?

Thank you in advance!

I’ve just found the solution.


curveNode=getNode('Centerline_Curve_left_2')
effect.self().markupNodeSelector.setCurrentNodeID(curveNode.GetID())
 
effect.self().importButton.click()