Why a rhinoObject does not always have a Mesh and how to create one?

Hi, i’m tring to work on meshes from a list of rhinoObjects.
But for some reason, some objects return an empty mesh list with the command .getMeshes. As you can see in my code below, i’ve tried to figure out a way out by creating a Brep, but that does not always works. Any idea?
(Generally the problematic objects are open surfaces or blocks instances)

Dim RhinoObjMeshs As Mesh() = RhinoObj.GetMeshes(MeshType.Any)
            If RhinoObjMeshs.Count = 0 Then
                If RhinoObj.Geometry.HasBrepForm Then
                    Dim RhinoBrep As Brep = Brep.TryConvertBrep(RhinoObj.Geometry)
                    Dim MyIfcFace = model.Instances.[New](Of Xbim.Ifc4.TopologyResource.IfcFace)()
                    Dim params As New Rhino.Geometry.MeshingParameters()
                    params.ComputeCurvature = False
                    params.GridAmplification = 0.5
                    RhinoObjMeshs = Mesh.CreateFromBrep(RhinoBrep, params)
                    RhinoApp.WriteLine("No BRep form: " & RhinoObj.Id.ToString)
                End If
            End If

Rhino only creates render meshes when it needs them. For example, create a sphere in wireframe mode. If you check the object, you won’t find a render mesh. Now shade a viewport. Notice the “Creating meshes…” message? If you re-check the object, it will not have a render mesh.

If needed, you can create the render meshes yourself by calling RhinoDoc.CreateMeshes. Here is code to a sample command that does this:


– Dale

Thank you so much Dale, it helped a lot.

For some reason your code did’nt work for blocks. My solution is to find the instance definitions, get its geometry, and apply the transform from the instance references to the meshes. I am not really sure that this is the best solution, what do you think about it?

Best Regards

 'Get Meshes
            Dim RhinoObjMeshs As Mesh()
            If RhinoObj.ObjectType = ObjectType.InstanceReference Then
                'Particular case for blocks
                Dim tpBlock As DocObjects.InstanceObject = RhinoObj
                Dim SubObjList = tpBlock.InstanceDefinition.GetObjects()
                Dim BlockMeshList As New List(Of Mesh)
                For Each SubObj In SubObjList
                    Dim SubObjMesh As New Mesh
                    SubObj.CreateMeshes(MeshType.Render, params, False)
                    Dim RhinoSubObjMeshs As Mesh() = SubObj.GetMeshes(MeshType.Render)
                    RhinoApp.WriteLine("Instance Definition MeshCount: " & RhinoSubObjMeshs.Count & "    /// Object:" & RhinoObj.Id.ToString)
                    For Each m As Rhino.Geometry.Mesh In RhinoSubObjMeshs
                Dim TPRhinoObjMeshs(BlockMeshList.Count - 1) As Mesh
                For SubMeshIndex As Integer = 0 To BlockMeshList.Count - 1
                    TPRhinoObjMeshs.SetValue(BlockMeshList(SubMeshIndex), SubMeshIndex)
                RhinoObjMeshs = TPRhinoObjMeshs
                RhinoObjMeshs = RhinoObj.GetMeshes(MeshType.Any)
                If RhinoObjMeshs.Count = 0 Then
                    RhinoObj.CreateMeshes(MeshType.Render, params, False)
                    RhinoObjMeshs = RhinoObj.GetMeshes(MeshType.Render)
                End If
            End If