GetMeshes question

var meshes = rh_obj.GetMeshes(MeshType.Render); in Rhino 7. does not work if the object type is SubD; :frowning_face: is there a method for Convert SubD GeometryBase to Mesh ? for Rhino 6?

If you convert ObjRef to Brep, then SubD may be converted to Mesh. works for Rhino 6 as well. :smiley:

Mesh mm = new Mesh();
            foreach (ObjRef objref0 in gs.Objects())
            {
                RhinoObject obj0 = objref0.Object();
          
                if (obj0 != null)
                {
                    if (objref0.Geometry() is Mesh mesh)
                    {
                        mm.Append(mesh);
                    }
                    else
                    {
                        Brep BrepS = objref0.Brep();
                        Mesh[] meshS2 = Mesh.CreateFromBrep(BrepS, MeshingParameters.QualityRenderMesh);
                        mm.Append(meshS2);
                    }
                   
                }
                obj0.Select(false);
            }
1 Like

Hi @taraskydon,

This works in Rhino 7:

import Rhino
import scriptcontext as sc

def test_getmeshes():
    filter = Rhino.DocObjects.ObjectType.AnyObject
    rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects("Select objects", False, filter)
    if rc != Rhino.Commands.Result.Success:
        return
        
    for objref in objrefs:
        rhobj = objref.Object()
        if not rhobj:
            return
        if not rhobj.IsMeshable:
            continue
        print(rhobj.ObjectType)
        meshType = Rhino.Geometry.MeshType.Render
        meshes = rhobj.GetMeshes(meshType)
        if not meshes:
            parameters = Rhino.Geometry.MeshingParameters.QualityRenderMesh 
            rhobj.CreateMeshes(meshType, parameters, False)
            rhobj.GetMeshes(meshType)
        if not meshes:
            print("No meshes returned")
        else:
            print(len(meshes))

if __name__ == "__main__":
    test_getmeshes()

– Dale

1 Like

This is one way, but you will get a remeshed result:

I don’t know if it is possible to get the rendermesh directly, but you can use the command “ExtractRendermesh” to get the subd mesh directly.

I tried your approach on other parts of the model and then it failed, so it seems to struggle with creating breps from all subds.

EDIT: Ignore this, Dales solution seems solid!

I use this method to get the Mesh only for the internal process inside the code, not to get the correct Mesh. for the correct Mesh you can specify your own Mesh parameter settings. I needed solutions to make the plugin I’m making work on Rhino 6 and 7 versions.

Thanks, I’ll translate to C# and check it out. That’s an option. :sunglasses: