# Anywhere to find a list of required inputs for Python?

**URL:** <https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546>\
**Category:** Support\
**Tags:** python, file-export, 3d-model\
**Created:** [November 28, 2017, 8:23pm UTC](https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546 "2017-11-28T20:23:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gbaltz](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gbaltz](https://discourse.slicer.org/u/gbaltz)\
**Post date:** [November 28, 2017, 8:23pm UTC](https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546/1 "2017-11-28T20:23:22Z")

</div>

Hello,

I am trying to write a Python script that can automate the export of a .stl model from a segmentation that is imported with the CT DICOM set.

I have pretty much everything by painfully looking through examples online, but I am stuck on how to do the final export.

I think this might be the code to use:

> slicer.modules.models.logic().SaveModel()

But that code requires two arguments and I have no way of figuring out what they are supposed to be. This is an issue I have run into with many other commands. Is there some database I can access that says what all the arguments for a code are supposed to be?

All i get back in the traceback error is:

> TypeError: SaveModel() takes exactly 2 arguments (0 given)

Which is next to useless as it doesn’t tell me what the arguments need to be.

---

<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:** [November 28, 2017, 8:45pm UTC](https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546/2 "2017-11-28T20:45:21Z")

</div>

You can use the `help` command to get documentation on any command. For example, enter this in the Python console:

```
help(slicer.modules.models.logic().SaveModel)

```

You can find full documentation of Slicer’s Python-wrapped C++ API at [http://apidocs.slicer.org](http://apidocs.slicer.org). Models module logic is documented here: [http://apidocs.slicer.org/master/classvtkSlicerModelsLogic.html#ae7123e56a176f06e0eda54403f07f393](http://apidocs.slicer.org/master/classvtkSlicerModelsLogic.html#ae7123e56a176f06e0eda54403f07f393)

---

<div class="post-metadata">

**Author:** ![gbaltz](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gbaltz](https://discourse.slicer.org/u/gbaltz)\
**Post date:** [November 29, 2017, 9:54pm UTC](https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546/3 "2017-11-29T21:54:11Z")

</div>

Thanks.

I’m having difficulty finding the vtkMRMLModelNode for the model I want to save. Is there a way to list all available?

Also will the SaveModel() save as .stl format?

It’s very confusing to me what stuff I have to use slicer.modules.models for and what stuff I have to use slicer.vtkMRMLModelNode() for

---

<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:** [November 30, 2017, 4:24am UTC](https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546/4 "2017-11-30T04:24:59Z")

</div>

Get list of all model nodes in the scene: use `slicer.util.getNodesByClass`. For example:

```
models=slicer.util.getNodesByClass('vtkMRMLModelNode')
for model in models:   
  if not model.GetHideFromEditors():
    print(model.GetName())

```

Save model as STL:

```
slicer.util.saveNode(modelNode, "c:/tmp/test.stl")

```

> [@gbaltz](#):
>
> It’s very confusing to me what stuff I have to use slicer.modules.models for and what stuff I have to use slicer.vtkMRMLModelNode()

Model node only stores the data, so you’ll only find methods in this class that are responsible getting/setting content. Any operation on the data is implemented in Models or other module logic classes or in utility functions.

---

<div class="post-metadata">

**Author:** ![gbaltz](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gbaltz](https://discourse.slicer.org/u/gbaltz)\
**Post date:** [November 30, 2017, 7:14pm UTC](https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546/5 "2017-11-30T19:14:57Z")

</div>

Once again, Thanks so much for your help.

Sorry to be a bother, I hope this is the last I have to ask for help.  
So I am trying to automate the step to export all segmentations as model that I can then save using the code you provided above.

So I have these segmentations. The Binary labelmap is currently master:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/7/6749a876415698723b06fce4e02f1d1bfb997e5a.png)

Then I have the following code to try to export them to models

> \>\>\>segmentations = slicer.util.getNodesByClass(‘vtkMRMLSegmentationNode’)  
> \>\>\>modelHierarchyNode = slicer.vtkMRMLModelHierarchyNode()  
> \>\>\>slicer.mrmlScene.AddNode(modelHierarchyNode)  
> \>\>\>slicer.modules.segmentations.logic().ExportAllSegmentsToModelHierarchy(segmentations[0],slicer.util.getNodesByClass(‘vtkMRMLModelHierarchyNode’)[0])

After the final line, the console returns “True” but no models appear, just this:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/5/c53fe7ca78af2aca52dc99fa584e9fd42f9ee715.png)

i am sure there is one step I am missing…

---

<div class="post-metadata">

**Author:** ![gbaltz](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gbaltz](https://discourse.slicer.org/u/gbaltz)\
**Post date:** [December 4, 2017, 5:29pm UTC](https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546/6 "2017-12-04T17:29:40Z")

</div>

Bump. Please see above. I’ve tried trouble shooting and I’m not sure where I am going wrong.

The ExportAllSegmentsToModelHierarchy() returns “True”, but no models appear under the ModelHierarchy node.

---

<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:** [December 4, 2017, 6:52pm UTC](https://discourse.slicer.org/t/anywhere-to-find-a-list-of-required-inputs-for-python/1546/7 "2017-12-04T18:52:26Z")

</div>

Thanks for the feedback. You’ve discovered a bug in `ExportAllSegmentsToModelHierarchy` method that I’ll fix in the nightly build today. Till then, or if you use the latest stable version, you can use `ExportSegmentsToModelHierarchy` method instead:

```
seg = getNode('Segmentation')
modelHierarchyNodeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLModelHierarchyNode')
segmentIds = vtk.vtkStringArray()
seg.GetSegmentation().GetSegmentIDs(segmentIds)
slicer.modules.segmentations.logic().ExportSegmentsToModelHierarchy(seg, segmentIds, modelHierarchyNodeNode)
```
