# Dynamic Modeler Module with python?

**URL:** <https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431>\
**Category:** Support\
**Created:** [September 11, 2020, 12:52am UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431 "2020-09-11T00:52:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [September 11, 2020, 12:52am UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/1 "2020-09-11T00:52:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [September 11, 2020, 2:54pm UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/2 "2020-09-11T14:54:26Z")

</div>

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:

```auto
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:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [September 18, 2020, 6:38pm UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/3 "2020-09-18T18:38:01Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [September 18, 2020, 7:34pm UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/4 "2020-09-18T19:34:10Z")

</div>

Sure, then you can use:

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

---

<div class="post-metadata">

**Author:** ![apparrilla](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/apparrilla/32/9230_2.png) [@apparrilla](https://discourse.slicer.org/u/apparrilla)\
**Post date:** [September 19, 2020, 12:10am UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/5 "2020-09-19T00:10:15Z")

</div>

It works like a charm, wonderfull.  
Thanks

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 19, 2020, 3:18pm UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/6 "2020-09-19T15:18:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tpereira](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@tpereira](https://discourse.slicer.org/u/tpereira)\
**Post date:** [July 2, 2021, 5:20pm UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/7 "2021-07-02T17:20:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 9, 2021, 4:27am UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/8 "2021-07-09T04:27:28Z")

</div>

You can create a new model node as any other node (`slicer.mrmlScene.AddNewNodeByClass`). See a complete example [here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#create-a-hollow-model-from-boundary-of-solid-segment).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 31, 2022, 7:23pm UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/9 "2022-10-31T19:23:52Z")

</div>

A post was split to a new topic: [Show/hide output model in Python script](https://discourse.slicer.org/t/show-hide-output-model-in-python-script/25988)

---

<div class="post-metadata">

**Author:** ![dimitris](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dimitris](https://discourse.slicer.org/u/dimitris)\
**Post date:** [April 9, 2025, 6:03pm UTC](https://discourse.slicer.org/t/dynamic-modeler-module-with-python/13431/10 "2025-04-09T18:03:25Z")

</div>

Hi,

I am a new member.  
Following your code in the case of curve cut tool I get:  
CurveCut.InputModel  
CurveCut.InputCurve  
CurveCut.InsidePoint

But then, if i try to implement an analogous code (eg in a case of sphere with a closed curve resampled and constrained)  
I get the error: ‘[VTK] Output node missing!’  
Does this error indicate that’ plane cut’ example is not applicable in a ‘curve cut’ case or am I doing something wrong?  
Here is the code I use:

inputModel = slicer.util.getNode(‘SphereModel’)  
inputCurve = slicer.util.getNode(‘CC’)  
insidePoint = slicer.util.getNode(‘F’)

outputPositive = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLModelNode”, “CutModel\_Positive”)  
outputPositive.CreateDefaultDisplayNodes()  
outputNegative = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLModelNode”, “CutModel\_Negative”)  
outputNegative.CreateDefaultDisplayNodes()

dynamicModelerNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLDynamicModelerNode”)  
dynamicModelerNode.SetToolName(“Curve cut”)  
dynamicModelerNode.SetNodeReferenceID(“CurveCut.InputModel”, inputModel.GetID())  
dynamicModelerNode.SetNodeReferenceID(“CurveCut.InputCurve”, inputCurve.GetID())  
dynamicModelerNode.SetNodeReferenceID(“CurveCut.InsidePoint”, insidePoint.GetID())  
dynamicModelerNode.SetNodeReferenceID(“CurveCut.OutputPositiveModel”, outputPositive.GetID())  
dynamicModelerNode.SetNodeReferenceID(“CurveCut.OutputNegativeModel”, outputNegative.GetID())

dynamicModelerNode.SetAttribute(“StraightCut”, “true”)  
dynamicModelerNode.SetAttribute(“Operation”, “Split”)  
dynamicModelerNode.SetAttribute(“InsideSurface”, “true”)  
dynamicModelerNode.SetAttribute(“OutsideSurface”, “true”)

slicer.modules.dynamicmodeler.logic().RunDynamicModelerTool(dynamicModelerNode)

Thanks in advance!
