# Export "vtkMRMLModelNode" as .OBJ

**URL:** https://discourse.slicer.org/t/export-vtkmrmlmodelnode-as-obj/28484
**Category:** Development
**Created:** [March 20, 2023, 7:36pm UTC](https://discourse.slicer.org/t/export-vtkmrmlmodelnode-as-obj/28484 "2023-03-20T19:36:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Contente](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/contente/32/65434_2.png) [@Contente](https://discourse.slicer.org/u/Contente)
#### Post date: [March 20, 2023, 7:36pm UTC](https://discourse.slicer.org/t/export-vtkmrmlmodelnode-as-obj/28484/1 "2023-03-20T19:36:13Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Contente](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/contente/32/65434_2.png) [@Contente](https://discourse.slicer.org/u/Contente)
#### Post date: [March 20, 2023, 9:13pm UTC](https://discourse.slicer.org/t/export-vtkmrmlmodelnode-as-obj/28484/2 "2023-03-20T21:13:08Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/7/07609ea8e08145784e69e50db32e38721419f622.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/3/93cae822c9947bf8728f5e0faef7e72c4f086f08.png)

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”

---

<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: [March 21, 2023, 1:32am UTC](https://discourse.slicer.org/t/export-vtkmrmlmodelnode-as-obj/28484/3 "2023-03-21T01:32:56Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![Contente](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/contente/32/65434_2.png) [@Contente](https://discourse.slicer.org/u/Contente)
#### Post date: [March 22, 2023, 1:36pm UTC](https://discourse.slicer.org/t/export-vtkmrmlmodelnode-as-obj/28484/4 "2023-03-22T13:36:14Z")

</div>

Such a simple solution…

Anyway, thanks a lot! It solved my problem.
