How can I retrieve the corresponding face(s) of a Brep edge? I've mentioned face with (s) because any non-naked edge will have normally have two faces joined“at the edge.
A Brep edge curve (IOnBrepEdge) knows of the trim curves (IOnBrepTrim) attached to it. And, a Brep trim curve know of it's owning Brep face (IOnBrepFace). Knowing this, we can loop through all of the trim curves, of an edge curve, and get the faces.
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select edge curve"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); IRhinoObject obj = go.Object(0).Object(); IOnBrep brep = go.Object(0).Brep(); IOnBrepEdge edge = go.Object(0).Edge(); if (null == obj || null == brep || null == edge) return IRhinoCommand.result.failure; MRhinoObjectAttributes attribs = new MRhinoObjectAttributes(obj.Attributes()); if (attribs.GroupCount() > 0) attribs.RemoveFromAllGroups(); for (int i = 0; i < edge.TrimCount(); i++) { IOnBrepTrim trim = edge.Trim(i); if (null != trim) { IOnBrepFace face = trim.Face(); if (null != face) { OnBrep face_brep = brep.DuplicateFace(face.m_face_index, true); if (null != face_brep) { MRhinoBrepObject face_brep_obj = context.m_doc.AddBrepObject(face_brep, attribs); if (null != face_brep_obj) face_brep_obj.Select(); } } } } context.m_doc.Redraw(); return IRhinoCommand.result.success; }