Save model as stl in RAS

Hi, at this time I’m trying to export the model node as RAS stl. Diving into documentation I saw that stl are saved as LPS by default, but it wont work for me…

Now I’m doing a quite simple process:

'Export segments to Models:'
    
    segmentationNode = slicer.util.getNode(segmentationName)
    segmentIDs = segmentationNode.GetSegmentation().GetSegmentIDs()
    segmentNames = [segmentationNode.GetSegmentation().GetSegment(segmentID).GetName() for segmentID in segmentIDs]
    'Create a folder to export models inside.'
    shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
    exportFolderItemId = shNode.CreateFolderItem(shNode.GetSceneItemID(), "Segments")
    slicer.modules.segmentations.logic().ExportSegmentsToModels(segmentationNode,segmentIDs, exportFolderItemId)type or paste code here


    modelNode = slicer.util.getNode(segmentName)
    stlPath = os.path.join(saveResults_path,segmentName)
    slicer.util.saveNode(modelNode, stlPath+'.stl')

You can control the coordinate system for a saved model by using the SetCoordinateSystem() method on the model storage node: Slicer: vtkMRMLModelStorageNode Class Reference

I think this should work:

modelStorageNode = modelNode.GetStorageNode()
modelStorageNode.SetCoordinateSystem(slicer.vtkMRMLStorageNode.CoordinateSystemRAS)
stlPath = os.path.join(saveResults_path,segmentName)
slicer.util.saveNode(modelNode, stlPath+'.stl')
1 Like