How can I pick a surface or polysurface and then generate a mesh from it?
See the following example.
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Pick a surface or polysurface to mesh MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select surface or polysurface to mesh"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); // Validate the geometry IOnBrep brep = go.Object(0).Brep(); if (null == brep) return IRhinoCommand.result.failure; // Get your favorite meshing parameters. If you want to modify one of these, then // just create a copy of one of these that you can modify. IOnMeshParameters fast_mp = RhUtil.RhinoApp().AppSettings().RenderMeshSettings().FastMeshParameters(); IOnMeshParameters quality_mp = RhUtil.RhinoApp().AppSettings().RenderMeshSettings().QualityMeshParameters(); IOnMeshParameters current_mp = context.m_doc.Properties().RenderMeshSettings(); // Create the meshes (1 for every brep face) OnMesh[] mesh_list = new OnMesh[0]; int mesh_count = brep.CreateMesh(current_mp, ref mesh_list); if (0 == mesh_count || 0 == mesh_list.Length) { RhUtil.RhinoApp().Print("Unable to mesh object.\n"); return IRhinoCommand.result.nothing; } // Create one big mesh from all of the mesh faces OnMesh mesh = new OnMesh(mesh_list[0]); for (int i = 1; i < mesh_count; i++) mesh.Append(mesh_list[i]); // TODO: do something with the mesh. // In is example, we'll just add it to the document. context.m_doc.AddMeshObject(mesh); context.m_doc.Redraw(); return IRhinoCommand.result.success; }