Create .stl file from segments

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:

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 :slight_smile:

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?