GHPython, triangulate mesh

unhandled

#1

Hello!
I wrote a GHPython script that takes a mesh as input and creates a mesh shell from it. It only makes sense with triangulated meshes, so, at first, I want to check if the input mesh has quad faces and triangulate it if so.

There’s a code example in the RhinoScriptSyntax docs:

import rhinoscriptsyntax as rs
obj = rs.GetObject(“Select mesh”, rs.filter.mesh )
if rs.MeshQuadCount(obj)>0:
rs.MeshQuadsToTriangles(obj)

This works when the Python component’s mesh input type hint is set to “ghdoc”.

However, I need the type hint set to “mesh”, because later in the code I use RhinoCommon access to mesh.TopologyVertices and mesh.TopologyEdges.

There does not seem to be a “triangulate” function in Rhino.Geometry.Mesh.

So, is there a way to get the mesh data from a Guid object?

Thanks!
Best regards
Eugen


(qythium) #2
mesh = rs.coercemesh(mesh_guid)

http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Collections_MeshFaceList_ConvertQuadsToTriangles.htm

The rhinoscriptsyntax code is open source on Github, so you can see how everything is done under the hood: https://github.com/mcneel/rhinoscriptsyntax/blob/15a1d3964703dffe798118f9b5583c93368e3634/Scripts/rhinoscript/mesh.py#L959


#3

=)
Thank you, sir! So, both ways are possible.
Best regards
Eugen