Export "vtkMRMLModelNode" as .OBJ

I have a segmentation that was converted into models in order to use the Surface Toolkit with them and access decimation and other optimization methods.

However, I want to export the models that have been processed to a .obj file, but the “slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsClosedSurfaceRepresentationToFiles()” only works for segments. Is there a way to do it without converting the models to a segmentation?

If not, how can I convert my models to a segmentation in python?


In order to simplify, I want to be able to do the following steps with Python scripts.

When I use “slicer.modules.segmentations.logic().ImportModelToSegmentationNode()” method, my Slicer3D stops for 30 minutes and crashes.

And the “slicer.util.saveNode(model, outputFileName)” gives this error:
Saving failed with all writers found for file “C:\Users\virtu\Desktop\python-slicer\obj_"muscle".obj” of type “ModelFile”

You can save models into OBJ files using slicer.util.exportNode function. For example:

modelNode = slicer.util.getNode('Model')
objFilePath = '/path/to/file.obj'
slicer.util.exportNode(modelNode, objFilePath)
1 Like

Such a simple solution…

Anyway, thanks a lot! It solved my problem.

1 Like