How to run Mesh Tools "Check Objects" in Python scripts to know if a mesh is valid?

Hello,

How can I run the Mesh ToolsCheck 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…

Regards,

Bruno

Hi @bmartin, you could script the Rhino command when your resulting mesh is selected:

import rhinoscriptsyntax as rs

def Check():
    mesh_id = rs.GetObject("Mesh to check", 32, True, True)
    if mesh_id:
        cmd = "_-Check _Clipboard"
        rc = rs.Command(cmd, False)
        if rc:
            print rs.ClipboardText()

Check()

You could then search the result of rs.ClipboardText() for the required data.

_
c.

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?

Cheers,

Bruno

Hi @bmartin,

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.

– Dale

Hello !

I would like to have the Check functionallity in RhinoCommon.

I try this:

import Rhino

Txt=Rhino.FileIO.TextLog()
Parm=Rhino.Geometry.MeshCheckParameters.NonManifoldEdgeCount

for obj in Rhino.RhinoDoc.ActiveDoc.Objects:
Result=obj.Geometry.Check(Txt,Parm)

But i get:

Message: expected MeshCheckParameters, got getset_descriptor

Can i have an Example please how to do ?

Hi @Simon21,

Try this:

import Rhino
import scriptcontext as sc

def test_mesh_checker():
    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)
            log.Print('\n')
    print(log.ToString())

if __name__=="__main__":    
    test_mesh_checker()

– Dale

Thanks ! Works fine !

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…