To get selected mesh edge, seems there is a function named MeshComponentRef in c++, but not in RhinoCommon, is there any method to get selected edge in RhinoCommon?
gf.Object(0).MeshComponentRef()
To get selected mesh edge, seems there is a function named MeshComponentRef in c++, but not in RhinoCommon, is there any method to get selected edge in RhinoCommon?
gf.Object(0).MeshComponentRef()
We just published a new extensive guide on rhinocommon in grasshopper. This is the section on meshes, does it help? Rhino - Chapter 3: RhinoCommon Geometry
Hi Scott,
I would like to get picked edge of mesh, just as the code below, but not cpp
CRhinoGetObject go;
go.SetCommandPrompt(L"Select mesh");
go.SetGeometryFilter(CRhinoGetObject::mesh_object);
go.GetObjects(1, 1);
if (go.CommandResult() != CRhinoCommand::success)
return go.CommandResult();
const CRhinoMeshObject* mesh_object = CRhinoMeshObject::Cast(go.Object(0).Object());
if (0 == mesh_object)
return CRhinoCommand::failure;
CRhGetMeshFaceRef gf(mesh_object->RuntimeSerialNumber());
gf.SetCommandPrompt(L"Select mesh edge");
gf.SetGeometryFilter(CRhinoGetObject::meshedge_filter);
gf.GetObjects(1, 1);
if (gf.CommandResult() != CRhinoCommand::success)
return gf.CommandResult();
const ON_MeshComponentRef* mesh_edge_ref = gf.Object(0).MeshComponentRef();
if (nullptr == mesh_edge_ref)
return CRhinoCommand::failure;
RhinoApp().Print(L"Selected mesh edge index = %d\n", mesh_edge_ref->MeshTopologyEdgeIndex());
The thread here:
is about faces but does it help?
I think this might be what you were trying to do:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
GetObject go = new GetObject();
go.GeometryFilter = ObjectType.MeshEdge;
while (true)
{
GetResult gr = go.Get();
if (gr == GetResult.Cancel)
return Result.Cancel;
if (gr == GetResult.Object)
{
ObjRef obj = go.Object(0);
if (obj.GeometryComponentIndex != null)
{
if (obj.GeometryComponentIndex.ComponentIndexType == ComponentIndexType.MeshTopologyEdge)
{
RhinoApp.WriteLine($"Selected topology edge {obj.GeometryComponentIndex.Index}");
}
}
break;
}
}
return Result.Success;
}
I think “GeometryComponentIndex.Index” is what I want, thanks.
great! it works well, thanks for your help