Using STL files with the help of Python


I need to generate python code which can import STL files and highlight/ tell the number of round surfaces in STL files.
So, far I have tried to use “Blender” and “OpenSCAD” but couldn’t succeed.

do you have any idea regarding this problem? Any kind of help would be appreciated.

Thanks in advance.


What are “round surfaces in STL”? STL’s are composed of triangles, by definition flat…



thank you for your reply.

yes, but I need to find circles on stl. for e.g if there is a cylinder, then I need to find that there are two surfaces which are in circle. Likewise, I need to create python code which could tell me the total number of circles in particular model.


OK, I wouldn’t know how to detect circle-like structures (they won’t be circles) within an object that is composed uniquely of triangles…



for e.g. My output should be as left hand side figure. it can be either graphically or just in numbers.


or can you guide me how can i generate python code from stl file. may be once I know the coordinates of this triangular elements, I can generate loop which can search equal distance from the face center. So if the distance is same, then I can allocate this as circle, if not then it would be thrown in non circle section.

(Willem Derks) #7

Hi Parth,

Thinking out loud here:

  • Import STL in Rhino
  • Use the command SplitDisjointMesh ( Or use a combination of weld/unweld and Explode to get separate mesh faces (eg the caps of a cylinder)
  • Analyze the disjoint mehses by comparing for instance it’s boundingbox center to the distance of vertices from that point.

All is dependent on the topology of the objects you import, how much they deviate from being truly circular, etc…



Along the same lines - I might just extract the mesh edges by scripting

_-ExtractMeshEdges ExtractMeshEdgesBy=BreakAngle

and some range of angles between 45° and 135°, then try to find closed planar curves, get their center, and then see if all the vertices are more or less the same distance from the center…



Thank you Willem and Mitch. As I have just started using Rhino, I will look for your suggestion and get back to you if I have any problem.


I tried to slice the surface and create the center of the face. But this procedure would be the manual, each time I have to do it manually which make no sense. Rather than I need to find some general python code which can directly lead me to the center of each surface step by step, by this I can check the distance from the center point,