# Load a .stl file and save it to a binary label map through

**URL:** <https://discourse.slicer.org/t/load-a-stl-file-and-save-it-to-a-binary-label-map-through/11315>\
**Category:** Support\
**Tags:** python, stl, nrrd\
**Created:** [April 27, 2020, 2:22pm UTC](https://discourse.slicer.org/t/load-a-stl-file-and-save-it-to-a-binary-label-map-through/11315 "2020-04-27T14:22:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xabierenko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xabierenko/32/6710_2.png) [@Xabierenko](https://discourse.slicer.org/u/Xabierenko)\
**Post date:** [April 27, 2020, 2:22pm UTC](https://discourse.slicer.org/t/load-a-stl-file-and-save-it-to-a-binary-label-map-through/11315/1 "2020-04-27T14:22:17Z")

</div>

Good afternoon,  
I’m trying to save a big bunch of .stl files to .nrrd binary label maps through python. I’m using the code below:

```
volume = slicer.util.loadVolume('C:\\Users\mreib\OneDrive - upf.edu\Burdeos\images\Bordeaux_Case1\image.mha', returnNode=True)
segmentation = slicer.util.loadSegmentation('C:\Users\mreib\OneDrive - upf.edu\Burdeos\Observer_1\case1_1.stl', returnNode=True)

labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode')

ids = vtk.vtkStringArray()
seg = getNode('case1_1')
seg.GetDisplayNode().GetVisibleSegmentIDs(ids)

slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode(seg, ids, 
labelmapVolumeNode, volume)

```

I keep getting the following error.

```
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: no overloads of ExportSegmentsToLabelmapNode() take 2 arguments

```

Thanks in advance!

---

<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:** [April 27, 2020, 4:23pm UTC](https://discourse.slicer.org/t/load-a-stl-file-and-save-it-to-a-binary-label-map-through/11315/2 "2020-04-27T16:23:14Z")

</div>

Type `help(slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode)` in the Python console or read the [API documentation](http://apidocs.slicer.org/master/classvtkSlicerSegmentationsModuleLogic.html) to get information on what parameters are needed.

You may also find the numerous [segmentation examples in script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Export_labelmap_node_from_segmentation_node) useful.

---

<div class="post-metadata">

**Author:** ![Xabierenko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xabierenko/32/6710_2.png) [@Xabierenko](https://discourse.slicer.org/u/Xabierenko)\
**Post date:** [April 27, 2020, 5:57pm UTC](https://discourse.slicer.org/t/load-a-stl-file-and-save-it-to-a-binary-label-map-through/11315/3 "2020-04-27T17:57:05Z")

</div>

I have managed to solve it, but thank you very much anyways! Now I have a problem running the script from the python interactor. I suppose it isn’t as simple as using ‘python Myscript.py’.

---

<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:** [April 27, 2020, 8:58pm UTC](https://discourse.slicer.org/t/load-a-stl-file-and-save-it-to-a-binary-label-map-through/11315/4 "2020-04-27T20:58:27Z")

</div>

It is almost as simple. You can use `PythonSlicer Myscript.py` (there are a couple of variants - see [here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Launching_Slicer)).

---

<div class="post-metadata">

**Author:** ![Xabierenko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xabierenko/32/6710_2.png) [@Xabierenko](https://discourse.slicer.org/u/Xabierenko)\
**Post date:** [April 27, 2020, 9:00pm UTC](https://discourse.slicer.org/t/load-a-stl-file-and-save-it-to-a-binary-label-map-through/11315/5 "2020-04-27T21:00:51Z")

</div>

Thanks for your help! I’m sorry for asking such simple questions.

---

<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 29, 2021, 12:34am UTC](https://discourse.slicer.org/t/load-a-stl-file-and-save-it-to-a-binary-label-map-through/11315/6 "2021-03-29T00:34:22Z")

</div>

2 posts were split to a new topic: [Combine STLs and export as NRRD](https://discourse.slicer.org/t/combine-stls-and-export-as-nrrd/16812)
