# Exporting models by script

**URL:** <https://discourse.slicer.org/t/exporting-models-by-script/8289>\
**Category:** Support\
**Created:** [September 4, 2019, 1:16pm UTC](https://discourse.slicer.org/t/exporting-models-by-script/8289 "2019-09-04T13:16:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ihsan\_MUTLU](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihsan_mutlu/32/4636_2.png) [@Ihsan\_MUTLU](https://discourse.slicer.org/u/Ihsan_MUTLU)\
**Post date:** [September 4, 2019, 1:16pm UTC](https://discourse.slicer.org/t/exporting-models-by-script/8289/1 "2019-09-04T13:16:10Z")

</div>

Hi!  
I am having a problem exporting models as obj files.  
I have created a model hierarcy node and filled it as follows:  
exportedModelsNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLModelHierarchyNode’)  
slicer.modules.segmentations.logic().ExportAllSegmentsToModelHierarchy(seg, exportedModelsNode)  
Now I want to get model nodes under newly created model hierarcy node with a for loop using below code.  
slicer.modules.models.logic().SaveModel(‘C:/Users/Desktop/aaa.obj’, **modelNode** )  
How can I get model nodes inside **exportedModelsNode**??

---

<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:** [September 4, 2019, 1:50pm UTC](https://discourse.slicer.org/t/exporting-models-by-script/8289/2 "2019-09-04T13:50:17Z")

</div>

I would recommend to use [slicer.modules.segmentations.logic().ExportSegmentsClosedSurfaceRepresentationToFiles()](https://apidocs.slicer.org/master/classvtkSlicerSegmentationsModuleLogic.html#a4b5328985b2d98cbbc93a5b2ae7fde6b) method directly.

---

<div class="post-metadata">

**Author:** ![Ihsan\_MUTLU](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihsan_mutlu/32/4636_2.png) [@Ihsan\_MUTLU](https://discourse.slicer.org/u/Ihsan_MUTLU)\
**Post date:** [September 4, 2019, 6:12pm UTC](https://discourse.slicer.org/t/exporting-models-by-script/8289/3 "2019-09-04T18:12:48Z")

</div>

Thanks, that did the job.  
Also, I managed to get nodes by:  
modelNodes = slicer.mrmlScene.GetNodesByClass(‘vtkMRMLModelNode’)
