Dynamic Modeler "Curve cut" creates output model node, but it's empty (no surface)

Hi everyone,

I’m trying to use the Dynamic Modeler module via Python scripting in 3D Slicer to cut a model using a curve. My goal is to keep only the inside portion of the model, and I’m not using the Straight Cut option. The script successfully creates a vtkMRMLDynamicModelerNode and the output model node (CurveCutOutput), but the output model does not contain any geometry – it’s an empty surface model.

Here is the core of my script:

modelNode = getNode("Model")
curveNode = getNode("Curve")
insidePointNode = getNode("F") 

curveCutModeler = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLDynamicModelerNode")
curveCutModeler.SetToolName("Curve cut")
curveCutModeler.SetNodeReferenceID("CurveCut.InputModel", modelNode.GetID())
curveCutModeler.SetNodeReferenceID("CurveCut.CuttingCurve", curveNode.GetID())

cutModelNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode", "CurveCutOutput")
curveCutModeler.SetNodeReferenceID("CurveCut.OutputModel", cutModelNode.GetID())

curveCutModeler.SetAttribute("CurveCut.UseStraightCut", "false")
curveCutModeler.SetAttribute("CurveCut.KeepCellsInside", "true")
curveCutModeler.SetAttribute("CurveCut.KeepCellsOutside", "false")
curveCutModeler.SetContinuousUpdate(True)

if not cutModelNode.GetDisplayNode():
    displayNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelDisplayNode")
    cutModelNode.SetAndObserveDisplayNodeID(displayNode.GetID())

cutModelNode.GetDisplayNode().SetOpacity(0.5)

I also tried this manually but the output is still empty:
slicer.modules.dynamicmodeler.logic().RunDynamicModelerTool(curveCutModeler)

What am I missing to get the surface generated in CurveCutOutput?
Is there a required event or trigger I’m not calling in the script? Or is there a known limitation or requirement of the Curve Cut tool when used programmatically?

Any advice or example of working code that produces a non-empty output model would be greatly appreciated!

Thanks in advance!

Is there any error in the console?

Curve cut does not always, work, it fails with some inputs. I don’t remember the exact error message but there was one about not finding a path or similar. You need to make yourself familiar with the tool and you’ll have an idea what is supposed to work and what is not.

Find some inputs on which it works when running from the GUI. Then you can verify your code and make sure it does the same thing.

Thank you for your response!

There is no error in the console, and the output model node is generated, but it’s marked with the comment: “Model !Invalid Model”. Please see the enclosed screenshot for reference.

Interestingly, when I use the Curve Cut tool manually through the GUI on the same model, curve, and point node, it works perfectly and produces the expected result. So the data itself seems fine, and the problem only arises during scripted execution.

I’ve tried multiple variations in the script (including toggling SetContinuousUpdate(False), changing the order of assignments, and manually calling slicer.modules.dynamicmodeler.logic().RunDynamicModelerTool(curveCutModeler)), but none led to a valid surface in CurveCutOutput.

As an alternative, I found a working approach using Kyle Sunderland’s clipping script:
:link: https://gist.github.com/Sunderlandkyl/b1e9c4def887a480eb6de8d45187f958
This script reliably clips the model using a plane and a closed curve, and fits my use case well.

I initially hoped to use the Dynamic Modeler tool for this task due to its integration and GUI correspondence, but unfortunately, the scripted version does not yield usable output in this scenario.

If anyone has insights into why the scripted Curve Cut doesn’t work despite the GUI version succeeding, I’d greatly appreciate further tips.

Thanks again!

Just a tip, I have found that sometimes when I see the “Model !Invalid model” message, actually most of the processing worked and there is data in the model node, but it failed some final validation check. It’s worth looking in the Models module to see if there are greater than zero Points and Cells listed in the model Information section. Sometimes you can even visualize the mesh. None of that turns it into a valid model node, but it can be helpful during debugging.
The most common issue I have run into is non-manifold edges. Sometimes some additional cleaning steps can resolve those. Is there a chance that curveCutModeler automatically applies some of that when called through the GUI but not through the methods you are calling?