Site Tools

Getting Brep Faces from Edges

Developer: .NET
Summary: Demonstrates how to obtain the face of a Brep given an edge.
Notice: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here.


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.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)
  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)
  return IRhinoCommand.result.success;

More Information

developer/getedgefaces.txt · Last modified: 2020/08/14 (external edit)