How can I run the Mesh Tools “Check Objects” command from a python script? If too impractical, is there another way to get the same kind of diagnostic information about a mesh from scripting?
Here is a little context:
I’m doing Boolean operations between 2 watertight meshes that sometimes produce invalid meshes. I would like to run the Mesh Tools Check Objects command on the resulting mesh. In case of problem, I would undo the operation and try again with one of the mesh translated just a little (generally solving the triangle/triangle intersection problem).
I need a good mesh as it will be used for 3D printing later…
Hi @bmartin, you could script the Rhino command when your resulting mesh is selected:
import rhinoscriptsyntax as rs
mesh_id = rs.GetObject("Mesh to check", 32, True, True)
cmd = "_-Check _Clipboard"
rc = rs.Command(cmd, False)
You could then search the result of
rs.ClipboardText() for the required data.
Thanks @clement, I’ll parse the clipboard and return a nice tuple giving the number of all the default types:
- degenerate faces
- extremely short edges.
- non manifold edges.
- naked edges.
- duplicate faces.
- faces with directions different from the mesh as a whole.
- self intersecting faces.
- disjoint pieces.
- unused vertices.
@dale Do you think this kind of information about meshes quality could be obtained more easily and robustly than by having to parse the clipboard from the Check command? Surely, there is underlying code called to get all this information? Is there a way to call it directly?
The mesh repair wizard (Panels > Mesh Repair) is written in RhinoCommon. So all this information is available in some form. For example, you can detect degenerate faces by calling MeshFaceList.GetZeroAreaFaces. Other calculations require some digging into the mesh. But all the information is there in RhinoCommon.
I would like to have the Check functionallity in RhinoCommon.
I try this:
for obj in Rhino.RhinoDoc.ActiveDoc.Objects:
But i get:
Message: expected MeshCheckParameters, got getset_descriptor
Can i have an Example please how to do ?
import scriptcontext as sc
log = Rhino.FileIO.TextLog()
log.IndentSize = 4
for rh_obj in sc.doc.Objects:
if isinstance(rh_obj, Rhino.DocObjects.MeshObject):
mcp = Rhino.Geometry.MeshCheckParameters.Defaults()
rc, mcp = rh_obj.MeshGeometry.Check(log, mcp)
Do you have a Mesh File for me for testing purposes where everything what is possible is invalid…
Try to produce a FIle like this without succes…