Script to use the Evaluate & Repair option for an stl mesh

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Valentina88
Posts: 1
Joined: Thu Nov 24, 2016 8:57 am

Script to use the Evaluate & Repair option for an stl mesh

Post by Valentina88 »

I tried to write a python script to import an stl mesh and then try to apply on it, within the mesh module, the option "Evaluate & Repair", and then export the repaired stl mesh overwriting the original file.
Is it possible to recall this option? I had no problem in importing the mesh module and the stl mesh but I do not know how to recall this option in the script, I did not find references in the documentation in order to do it.

Thank you in advance
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Script to use the Evaluate & Repair option for an stl mesh

Post by wmayer »

Try this:

Code: Select all

mesh = ...
mesh.harmonizeNormals() # fixes the orientation if needed
mesh.removeNonManifolds() # removes all triangles when an edge is shared by more than two triangles
mesh.fixIndices() # fixes errors in the actual data structure
mesh.fixDegenerations() # tries to fix degenerations by either splitting or removing triangles
mesh.removeDuplicatedFacets()
mesh.removeDuplicatedPoints()
mesh.fixSelfIntersections() # removes all triangles involved in a self-intersection
rkneills
Posts: 6
Joined: Wed Mar 06, 2019 1:55 pm

Re: Script to use the Evaluate & Repair option for an stl mesh

Post by rkneills »

Thanks for those repair functions wmayer. Is there a python function that will evaluate the mesh to check and return if it is broken or not? Would it be possible to add if not? Thanks again.
Post Reply