# Obtain STL information without exporting segment

**URL:** <https://discourse.slicer.org/t/obtain-stl-information-without-exporting-segment/26236>\
**Category:** Support\
**Created:** [November 14, 2022, 3:37pm UTC](https://discourse.slicer.org/t/obtain-stl-information-without-exporting-segment/26236 "2022-11-14T15:37:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [November 14, 2022, 3:37pm UTC](https://discourse.slicer.org/t/obtain-stl-information-without-exporting-segment/26236/1 "2022-11-14T15:37:01Z")

</div>

Hi,

I have a Python script that works with .stl files. In order to speed things up in Slicer, I would like to get the information from the .stl file without having to export it. Is it possible?

Thanks 😀

---

<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:** [November 14, 2022, 6:17pm UTC](https://discourse.slicer.org/t/obtain-stl-information-without-exporting-segment/26236/2 "2022-11-14T18:17:10Z")

</div>

I guess you mean you would want to export to file without exporting to model node. You can do that by-right-clicking “Export to files…” function (in drop-down menu of the green right-arrow button in Segment Editor).

This feature is avaiable in the method: [slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsClosedSurfaceRepresentationToFiles()](https://apidocs.slicer.org/main/classvtkSlicerSegmentationsModuleLogic.html#a4b5328985b2d98cbbc93a5b2ae7fde6b)

---

<div class="post-metadata">

**Author:** ![Atsui\_75](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/atsui_75/32/16046_2.png) [@Atsui\_75](https://discourse.slicer.org/u/Atsui_75)\
**Post date:** [November 15, 2022, 12:01pm UTC](https://discourse.slicer.org/t/obtain-stl-information-without-exporting-segment/26236/3 "2022-11-15T12:01:33Z")

</div>

Hi!

I have created this function from information of different forums to get vertices and faces of segmentation in Slicer directly as numpy arrays. It works thanks to the module pyvista.

```auto

def polydata(segmentation = 'Segmentation', segment = 'Segment_1'):
    segmentationNode = slicer.util.getNode(segmentation)
    segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(segment)
    
    superficie = vtk.vtkPolyData()
    slicer.vtkSlicerSegmentationsModuleLogic.GetSegmentClosedSurfaceRepresentation(segmentationNode, segmentId, superficie, True)
    
    return pyvista.PolyData(superficie)

```

Is this what you are looking for?

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [November 15, 2022, 2:57pm UTC](https://discourse.slicer.org/t/obtain-stl-information-without-exporting-segment/26236/4 "2022-11-15T14:57:51Z")

</div>

That’s it!

Grazas 🙂
