Dynamic Modeler Module with python?

Slicer: 4.11.0-2020-07-04 r29204 Win10

I want to use Dynamic Modeler Module Plane Cut tool (and others) with python. Is there any documentation published?

Thanks.

No documentation pages have been published yet, although one should probably be created.

You can display all of the input node references for a tool using the following:

planeCutTool = slicer.vtkSlicerDynamicModelerPlaneCutTool()
for i in range(planeCutTool.GetNumberOfInputNodes()):
  print(planeCutTool.GetNthInputNodeReferenceRole(i))

The node references can be used to create a dynamic modeler node:

dynamicModelerNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLDynamicModelerNode")
dynamicModelerNode.SetToolName("Plane cut")
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputModel", inputmodelNode.GetID())
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputPlane", inputPlaneNode.GetID())
dynamicModelerNode.SetNodeReferenceID("PlaneCut.OutputPositiveModel", outputModel.GetID())
slicer.modules.dynamicmodeler.logic().RunDynamicModelerTool(dynamicModelerNode)
1 Like

Thanks so much @Sunderlandkyl.
Just a bit more info:

  • I need to add more than one InputPlane
  • I should like to look around with Parameters (Operation Type)

Thanks on advance!

Sure, then you can use:

  • AddNodeReferenceID instead of SetNodeReferenceID for the plane node
  • SetAttribute(“OperationType”, type), where type is “Union”, “Intersection”, or “Difference”.
1 Like

It works like a charm, wonderfull.
Thanks

@Sunderlandkyl could you add these to the documentation in header files? Thank you!

1 Like

This has been very helpful, but if I wanted to create a new model for the output is there a way I could do that. Or a way to create an empty model I could output too.

You can create a new model node as any other node (slicer.mrmlScene.AddNewNodeByClass). See a complete example here.

A post was split to a new topic: Show/hide output model in Python script