Got mesh face with MRhinoGetObject, need that face's parent mesh objref as well


#1

I’m working in C# with Rhino.Net SDK building commands for a plug-in.

I’ve picked up the user’s GUI-selection of a MeshFace with MRhinoGetObject, via

 MRhinoGetObject go = new MRhinoGetObject();
 ...
 ... (filter for mesh face)
 IOnMeshFaceRef pFace = go.Object(i).MeshFace();

, now I need the (IRhinoObjectRef) reference to the parent Mesh of that selected Face. (I need it so I can later do a context.m_doc.ReplaceObject() ) I thought it might be something like:

IRhinoObjRef origMesh = go.Object(i).m_parent_geometry; – or some cast of that or similar,

but its not. I have no trouble getting (a copy of) the parent mesh itself by
OnMesh mesh = new OnMesh(pFace.m_mesh);

, but I don’t know how to get an IRhinoObjRef of that.

??


(Dale Fugier) #2

Does this help?

MRhinoGetObject go = new MRhinoGetObject();
go.SetCommandPrompt("Select mesh face to remove");
go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.meshface_object);
go.EnableSubObjectSelect(true);
go.GetObjects(1, 1);
if (go.CommandResult() != IRhinoCommand.result.success)
  return go.CommandResult();

IRhinoObjRef obj_ref = go.Object(0);
IRhinoObject obj = obj_ref.Object();
if (null == obj)
  return IRhinoCommand.result.failure;

IOnMeshFaceRef face_ref = obj_ref.MeshFace();
if (null != face_ref)
{
  IOnMesh mesh = face_ref.m_mesh;
  if (null != mesh)
  {
    OnMesh new_mesh = new OnMesh(mesh);
    new_mesh.m_F.Remove(face_ref.m_mesh_fi);
    new_mesh.Compact();
    context.m_doc.ReplaceObject(new MRhinoObjRef(obj), new_mesh);
    context.m_doc.Redraw();
  }
}

return IRhinoCommand.result.success;

#3

Dale,

Yes, thank you.

Peter Schwenn