Skip to content

Instantly share code, notes, and snippets.

@somada141
Last active January 27, 2022 06:46
Show Gist options
  • Save somada141/bee83f2573c521786fb0 to your computer and use it in GitHub Desktop.
Save somada141/bee83f2573c521786fb0 to your computer and use it in GitHub Desktop.
Load an the contents of an STL file into a vtkPolyData object with Python and VTK #python #vtk #fileIO #visualizaton #stl

Assuming we have an .stl file under filenameSTL we can load the contents of that file using the vtkSTLReader class as such:

readerSTL = vtk.vtkSTLReader()
readerSTL.SetFileName(filenameSTL)
# 'update' the reader i.e. read the .stl file
readerSTL.Update()

polydata = readerSTL.GetOutput()

# If there are no points in 'vtkPolyData' something went wrong
if polydata.GetNumberOfPoints() == 0:
    raise ValueError("No point data could be loaded from '" + filenameSTL)
@abhishek9299
Copy link

how can i get no of triangles on a mesh ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment