Python: Referencing a Selected Surface / Brep Edge

Question 1: How do I reference the user selected edge. It turns out component index does not always align with the index in Geometry.Edges. How do I use the component index from Rhino.Input.Custom to reference the selected edge within the surface / brep?

Question 2: Is there an easy way to copy the selected edge?

If you run the Python code and select the edge shown below, the code tries to copy it referencing Geometry.Edges with the Component Index and it adds a new line but it’s the wrong edge, so Component Index does not equal the index within Geometry.Edges.

Copy Edge.3dm (61.8 KB)
McNeel Test.py (1.3 KB)

Hi Mike - try

  edge = r.Geometry()
  sc.doc.Objects.AddCurve(edge.Duplicate())

alternatively

    brep = r.Brep()
    edge = brep.Edges[idx]

-Pascal

Hey Pascal…

edge.Duplicate works great for copying the edge, but the alternative method does not access the correct edge. Here’s the revised code that I tried. It’s still acting like what I described above where if I duplicate it by the PointAtStart and PointAtEnd points, it’s referencing the wrong edge.

Any ideas?

    brep = r.Brep()
    edge = brep.Edges[idx]

    line = rs.AddLine(edge.PointAtStart, edge.PointAtEnd)

At this point I am trying to understand how to access the correct edge in the brep object via it’s Edges list when I have the Component Index from GetObject method.

Is GetObject returning the wrong Component Index?

Ah yes - the component index is a BrepTrim, not an edge - my bad, sorry about that - try

brep = r.Brep()
e = brep.Trims[idx].Edge
print(sc.doc.Objects.AddCurve(e.Duplicate()))

You can check with
iType = r.GeometryComponentIndex.ComponentIndexType

-Pascal

Ok thanks!!! That makes sense now.