Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:getedgefaces [2015/09/14]
developer:rhinocommonsamples:getedgefaces [2020/08/14] (current)
Line 1: Line 1:
 +===== Sample: Getting Brep Faces from Edges =====
 +
 +===== C# =====
 +<code c#>
 +public class GetEdgeFacesCommand : Command
 +{
 +  public override string EnglishName { get { return "csGetEdgeFaces"; } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    ObjRef obj_ref;
 +    var rc = RhinoGet.GetOneObject(
 +      "Select edge curve", false, ObjectType.EdgeFilter, out obj_ref);
 +    if (rc != Result.Success)
 +      return rc;
 +    var edge = obj_ref.Edge();
 +
 +    var face_idxs = edge.AdjacentFaces();
 +    var edge_owning_brep = edge.Brep;
 +
 +    foreach (var idx in face_idxs)
 +    {
 +      var face = edge_owning_brep.Faces[idx];
 +      var face_copy = face.DuplicateFace(true);
 +      var id = doc.Objects.AddBrep(face_copy);
 +      doc.Objects.Find(id).Select(true);
 +    }
 +    doc.Views.Redraw();
 +    return Result.Success;
 +  }
 +}
 +</code>
 +===== VB.NET =====
 +<code vb>
 +Public Class GetEdgeFacesCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "vbGetEdgeFaces"
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim obj_ref As ObjRef = Nothing
 +    Dim rc = RhinoGet.GetOneObject("Select edge curve", False, ObjectType.EdgeFilter, obj_ref)
 +    If rc <> Result.Success Then
 +      Return rc
 +    End If
 +    Dim edge = obj_ref.Edge()
 +
 +    Dim face_idxs = edge.AdjacentFaces()
 +    Dim edge_owning_brep = edge.Brep
 +
 +    For Each idx As Integer In face_idxs
 +      Dim face = edge_owning_brep.Faces(idx)
 +      Dim face_copy = face.DuplicateFace(True)
 +      Dim id = doc.Objects.AddBrep(face_copy)
 +      doc.Objects.Find(id).[Select](True)
 +    Next
 +    doc.Views.Redraw()
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</code>
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.Commands import *
 +from Rhino.DocObjects import *
 +from Rhino.Input import *
 +from scriptcontext import doc
 +
 +def RunCommand():
 +  rc, obj_ref = RhinoGet.GetOneObject(
 +    "Select edge curve", False, ObjectType.EdgeFilter)
 +  if rc <> Result.Success:
 +    return rc
 +  edge = obj_ref.Edge()
 +
 +  face_idxs = edge.AdjacentFaces()
 +  edge_owning_brep = edge.Brep
 +
 +  for idx in face_idxs:
 +    face = edge_owning_brep.Faces[idx]
 +    face_copy = face.DuplicateFace(True)
 +    id = doc.Objects.AddBrep(face_copy)
 +    doc.Objects.Find(id).Select(True)
 +
 +  doc.Views.Redraw()
 +  return Result.Success
 +
 +if __name__ == "__main__":
 +  RunCommand()
 +</code>
 +
 +{{tag>Developer rhinocommon}}