Site Tools


This is an old revision of the document!


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

Question

I would to know 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.

Answer

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.

Example

C#

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;
}

More Information

developer/getedgefaces.1442255296.txt.gz · Last modified: 2016/01/22 (external edit)