Model Plane Cutting

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

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)

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

Ex.

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

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

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.

I have tried:

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:

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

‘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.

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.

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

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

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)
2 Likes