RhinoCommon c# method to duplicate surface edge

Is there a method similar to Rhino command, “DupEdge”?

I tried:

        Rhino.Geometry.Curve[] curves = brep.DuplicateEdgeCurves(true);

But this gives me the entire boundary curve. I need just one edge of the surface, so I can supply it with a name.

Hi @cestes001,

Just call DuplicateCurve on the specific edge.

var curve = brep.Edges[0].DuplicateCurve();

– Dale

How do I Select an edge of the surface?

When I selectthe surface to extract the boundary from, the surface remains highlighted and no curves are created or highlighted.

You select the edges by their index as per Dale’s example. What are you trying to accomplish?

There are surfaces or polysurfaces that I want to duplicate one or more of the edges of. I’d like to click on the edge and have a curve or curves created that duplicate the selected edge. The code should emulate the Rhino dupEdge command.

Once selected, I want to apply a name to that curve and then move on to another edge or to an edge of another surface.

So far, I haven’t been able to find how to do the selection. Once I have that, I already have the ability to add a name to it, but I’m missing some piece of the process for selecting the edge.

Hi @cestes001

If you get the edges with a GetObject (go), you should be able to find the index with:

for (int i = 0; i < go.ObjectCount; i++)
{
    int edgeIndex = go.Object(i).Geometry().ComponentIndex().Index;
}

Finally getting back to this problem.

In normal Rhino modeling, the user issues the dupEdge command and selects the desired edge. Without further ado, the edge is duplicated and the resulting curve is left selected.

What I need to do is have the user click on the desired edge and have the plugin determine which edge was selected. In the current (and typical) case, there are eight edges.

I have the code to handle the selection, duplication and naming, but I need to know which Brep edge was clicked on.

var curve = brep.Edges[i].DuplicateCurve();

depends on knowing the value of i, which is where I’m stumped.

Which I was pretty positive you get with the method I posted. What am I missing?

The variable, i, has a value between zero and the number of edges minus 1. I’ve selected only one of those multiple edges. I want the plugin to determine which of those edges I selected. I only want one edge, not all of them.

Accordingly, as i traverse the following array of edges:

for (int i = 0; i < go.ObjectCount; i++)

I want to know what the index (i) of that one edge is, so I can cause a curve to be created on that edge and not on any of the rest of the edges.

I’ve found a solution. Not sure how elegant it is, but it seems to work.

        Rhino.DocObjects.ObjRef obj_ref;
        var rc = RhinoGet.GetOneObject("Select surface", false, ObjectType.Surface, out obj_ref);
        if (rc != Result.Success || obj_ref == null)
            return rc;
        var brep = obj_ref.Brep();

        var gp = new GetPoint();
        gp.SetCommandPrompt("Click on edge");
        gp.Get();
        int edgeIndex = 0;
        Point3d pickedPt = gp.Point();
        double ptClosest = 2000;
        double t;
        for (int i = 0; i < brep.Edges.Count; i++)
        {
            Curve crv = brep.Edges[i];
            if (crv.ClosestPoint(pickedPt, out t, 1))
            {
                if (t < ptClosest)
                {
                    ptClosest = t;
                    edgeIndex = i;
                }
            }
        }
        var curve = brep.Edges[edgeIndex].DuplicateCurve();
        ObjectAttributes objAtt = new ObjectAttributes();

        System.Guid edgeGuid = doc.Objects.AddCurve(curve,objAtt);
1 Like