Sdk Curve Reverse
Last changed: -198.145.97.157

.
Developer.NET
SummaryDemonstrates how to reverse the direction of curves using the Rhino SDK.

Question

I am trying to reverse the direction of a curve that I have selected. I found that there is a OnCurve.Reverse method, but I do not know how to use it.

Answer

In order to modify any geomatric object that exists in Rhino, you must:

  1. Get the object.
  2. Make a copy of it.
  3. Modify the copy.
  4. Replace the original object with the copy.

The following code sample demonstrates how to reverse the direction of one or more curves.

C#

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    MRhinoGetObject go = new MRhinoGetObject();
    go.SetCommandPrompt("Select curves to reverse");
    go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
    go.GetObjects(1, 0);
    if (go.CommandResult() != IRhinoCommand.result.success)
      return go.CommandResult();


    for (int i = 0; i < go.ObjectCount(); i++)
    {
      IRhinoObjRef obj_ref = go.Object(i);
      IOnCurve crv = obj_ref.Curve();
      if( crv != null)
      {
        OnCurve dupe = crv.DuplicateCurve();
        if( dupe != null )
        {
          dupe.Reverse();
          context.m_doc.ReplaceObject(obj_ref, dupe);
        }
      }
    }


    context.m_doc.Redraw();
    return IRhinoCommand.result.success;
  }