# Create .stl file from segments

**URL:** <https://discourse.slicer.org/t/create-stl-file-from-segments/33619>\
**Category:** Support\
**Tags:** segmentation, stl\
**Created:** [January 4, 2024, 9:57am UTC](https://discourse.slicer.org/t/create-stl-file-from-segments/33619 "2024-01-04T09:57:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SANTIAGO\_PENDON\_MING](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/santiago_pendon_ming/32/66060_2.png) [@SANTIAGO\_PENDON\_MING](https://discourse.slicer.org/u/SANTIAGO_PENDON_MING)\
**Post date:** [January 4, 2024, 9:57am UTC](https://discourse.slicer.org/t/create-stl-file-from-segments/33619/1 "2024-01-04T09:57:53Z")

</div>

Hi to everyone. Today’s question is quite ‘easy’ but, after look the wiki and older post I didn’t see anything… I’m trying to convert my segment into .stl files with Python code.

I’m acquainted with segmentations and segment editor modules and I know you can export segments to .stl file using a volume reference and specifying the coordinates system. However, I couldn’t find the code lines to do that.

I guess it should start something like:

```auto
node = slicer.util.getNode('Segmentation')
segmentName = 'Segment_1'
segmentIndex= node.GetSegmentation().GetSegmentIdBySegmentName(segmentName )
node.Function.....

```

Has somebody idea of what function performs this? And what parameters uses?

Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![SANTIAGO\_PENDON\_MING](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/santiago_pendon_ming/32/66060_2.png) [@SANTIAGO\_PENDON\_MING](https://discourse.slicer.org/u/SANTIAGO_PENDON_MING)\
**Post date:** [January 4, 2024, 11:18am UTC](https://discourse.slicer.org/t/create-stl-file-from-segments/33619/2 "2024-01-04T11:18:47Z")

</div>

```auto
segmentationNode = getNode("Segmentation")
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
exportFolderItemId = shNode.CreateFolderItem(shNode.GetSceneItemID(), "Segments")
slicer.modules.segmentations.logic().ExportAllSegmentsToModels(segmentationNode, exportFolderItemId)

```

I think using this will work. Also what I have to do if I only one one segment and not all?
