# Model Plane Cutting

**URL:** <https://discourse.slicer.org/t/model-plane-cutting/30556>\
**Category:** Support\
**Created:** [July 12, 2023, 3:48pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556 "2023-07-12T15:48:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [July 12, 2023, 3:48pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/1 "2023-07-12T15:48:37Z")

</div>

How can I set the InputPlane parameter to RED plane?  
Because I want it to do the cutting on the RED plane.

```auto
dynamicModelerNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLDynamicModelerNode")                
dynamicModelerNode.SetToolName("Plane cut")                
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputModel", InputModelNode.GetID())                
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputPlane", "Red")
dynamicModelerNode.SetNodeReferenceID("PlaneCut.OutputPositiveModel", InputModelNode.GetID())
slicer.modules.dynamicmodeler.logic().RunDynamicModelerTool(dynamicModelerNode)

```

---

<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:** [July 12, 2023, 3:54pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/2 "2023-07-12T15:54:01Z")

</div>

You need to specify the “Red” slice node ID.

Ex.

```python
redSliceNode = slicer.util.getFirstNodeByClassByName("vtkMRMLSliceNode", "Red")
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputPlane", redSliceNode.GetID())

```

---

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [July 12, 2023, 6:04pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/3 "2023-07-12T18:04:21Z")

</div>

Thank you for quick reply

But there is no Red slice node.  
So i can not use getnode.  
i need to set the plane node parameter of the dynamic model object as RED.  
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:** [July 12, 2023, 6:19pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/4 "2023-07-12T18:19:57Z")

</div>

If there isn’t a Red slice node, then you can’t set it as an input. It also wouldn’t appear in any view layouts.

There should always be a red slice node in the scene if you are running a Slicer GUI.

---

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [July 12, 2023, 6:31pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/5 "2023-07-12T18:31:39Z")

</div>

I have tried:

```auto
redSliceNode = slicer.util.getNodesByClass('vtkMRMLSliceNode','Red')
dynamicModelerNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLDynamicModelerNode")                
dynamicModelerNode.SetToolName("Plane cut")                
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputModel", InputBeyinModelNode.GetID())                
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputPlane", redSliceNode.GetID())
dynamicModelerNode.SetNodeReferenceID("PlaneCut.OutputPositiveModel", InputBeyinModelNode.GetID())
slicer.modules.dynamicmodeler.logic().RunDynamicModelerTool(dynamicModelerNode)

```

but, the error:

```auto
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputPlane", redSliceNode.GetID())
AttributeError: 'list' object has no attribute 'GetID'

```

---

<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:** [July 12, 2023, 6:37pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/6 "2023-07-12T18:37:07Z")

</div>

‘getNodesByClass’ returns a list of all "vtkMRMLSliceNodes in the scene ([Red, Green, Yellow]).

getFirstNodeByClassByName returns only a single node with the specified class name and node name.

---

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [July 12, 2023, 6:55pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/7 "2023-07-12T18:55:45Z")

</div>

After loading model file, the Red, Green and Yellow slices remain beyond the model.  
I guess that’s why the Red slice plane cut isn’t doing any work.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/0/e0437ccf9c8a9ab353b128bac8170acbb1000a4e.png)

---

<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 12, 2023, 7:16pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/8 "2023-07-12T19:16:57Z")

</div>

It is all good then. If you only work with models (no image) then probably you want to use markup plane nodes for cutting.

---

<div class="post-metadata">

**Author:** ![Muhammed\_Fatih\_Talu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muhammed_fatih_talu/32/14646_2.png) [@Muhammed\_Fatih\_Talu](https://discourse.slicer.org/u/Muhammed_Fatih_Talu)\
**Post date:** [July 12, 2023, 7:20pm UTC](https://discourse.slicer.org/t/model-plane-cutting/30556/9 "2023-07-12T19:20:23Z")

</div>

I solved the problem.  
Thanks Sunderland and Lasso  
The solution is as below:

```auto
pointCoordinates = slicer.util.arrayFromModelPoints(InputBeyinModelNode)
import numpy as np
position = np.average(pointCoordinates, axis=0)

# Center slice views and cameras on this position                
for sliceNode in slicer.util.getNodesByClass('vtkMRMLSliceNode'):
    sliceNode.JumpSliceByCentering(*position)
for camera in slicer.util.getNodesByClass('vtkMRMLCameraNode'):
    camera.SetFocalPoint(position)              
    
# red slicedan kes
redSliceNode = slicer.util.getFirstNodeByClassByName("vtkMRMLSliceNode", "Red")

dynamicModelerNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLDynamicModelerNode")                
dynamicModelerNode.SetToolName("Plane cut")                
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputModel", InputBeyinModelNode.GetID())                
dynamicModelerNode.SetNodeReferenceID("PlaneCut.InputPlane", redSliceNode.GetID())
dynamicModelerNode.SetNodeReferenceID("PlaneCut.OutputPositiveModel", OutputBeyinModelNode.GetID())
slicer.modules.dynamicmodeler.logic().RunDynamicModelerTool(dynamicModelerNode)

```
