# How to make a model available in CLI Python modules

**URL:** <https://discourse.slicer.org/t/how-to-make-a-model-available-in-cli-python-modules/41662>\
**Category:** Support\
**Created:** [February 13, 2025, 12:33am UTC](https://discourse.slicer.org/t/how-to-make-a-model-available-in-cli-python-modules/41662 "2025-02-13T00:33:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![modenaxe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/modenaxe/32/79405_2.png) [@modenaxe](https://discourse.slicer.org/u/modenaxe)\
**Post date:** [February 13, 2025, 12:33am UTC](https://discourse.slicer.org/t/how-to-make-a-model-available-in-cli-python-modules/41662/1 "2025-02-13T00:33:41Z")

</div>

Hello,  
I am writing a CLI module and would like to have a model as an input to then use it as vtkPolyData. I have checked the [provided example](https://github.com/lassoan/SlicerPythonCLIExample/) and inspected some of the C++ modules taking a model as input, for example [ModelToLabelMap](https://github.com/Slicer/Slicer/blob/e6971c540b030f7e83f949918a433cf58bee4c3b/Modules/CLI/ModelToLabelMap/ModelToLabelMap.cxx) but it is still unclear to me how to do it.  
I am trying some code resembling the C++ code but it is not working because ReadData cannot read the ModelNode:

```auto
modelNode = slicer.vtkMRMLModelNode()
modelStorageNode = slicer.vtkMRMLModelStorageNode()
modelStorageNode.SetFileName(sys.argv[1]) # sys.argv[1] is the input model provided by the GUI
modelNode = modelStorageNode.ReadData(modelNode)
polyModel = modelNode.getPolyData()

```

I have two questions:

1. How can this be achieved in Python? (Apologies if this is obvious, I am just getting started with Slicer).
2. what is the best way of practically developing a CLI module autogenerated GUI? Currently I am finding myself restarting Slicer every time I modify the GUI xml.

Thank you for any insight,  
Luca

---

<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:** [February 13, 2025, 4:20am UTC](https://discourse.slicer.org/t/how-to-make-a-model-available-in-cli-python-modules/41662/2 "2025-02-13T04:20:04Z")

</div>

Your code snippet is generally OK, it just has a few errors. Something like this should work better:

```python
    import slicer
    modelNode = slicer.vtkMRMLModelNode()
    modelStorageNode = slicer.vtkMRMLModelStorageNode()
    modelStorageNode.SetFileName(sys.argv[1]) # sys.argv[1] is the input model provided by the GUI
    success = modelStorageNode.ReadData(modelNode)
    polydata = modelNode.GetPolyData()

```

---

<div class="post-metadata">

**Author:** ![modenaxe](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/modenaxe/32/79405_2.png) [@modenaxe](https://discourse.slicer.org/u/modenaxe)\
**Post date:** [February 13, 2025, 4:45am UTC](https://discourse.slicer.org/t/how-to-make-a-model-available-in-cli-python-modules/41662/3 "2025-02-13T04:45:09Z")

</div>

Thank you for the prompt reply, Andras, this is indeed working! I was importing slicer but did not notice the lower ‘g’.
