Create/draw line markup from scripted module

Hello Slicer Community,

I’m new to the Slicer world so I apologize in advance if I make any mistakes.

I am creating a small module that allows you to manage needles on images (import, visual control, modification, export). Basically, a needle is a line markup.

here a preview of the module

Currently, I can load a control file, create needles (line markup) in the scene, and re-export the data from the scene.

My biggest problem now is that I want to create a line markup from scratch (no coordinates). In fact I have to repeat/simulate the click on the “create line markup” button in the Markups module : this activates the “drawing mode” which allows to select the 2 control points of the line on the scenes.

I don’t see how to do it, nor if it is possible from a scripted module,

Could someone help me ?

Thanks

You can use the markup place widget for this. See this script repository example.

1 Like

Thanks @lassoan it was exactly was I excepted !

For those interested the code used

selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
selectionNode.SetReferenceActivePlaceNodeClassName("vtkMRMLMarkupsLineNode")
interactionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLInteractionNodeSingleton")
interactionNode.SwitchToSinglePlaceMode()
2 Likes