Site Tools


Reversing the Direction of Curves

.NET

Summary: Demonstrates how to reverse the direction of curves using the Rhino SDK.
NOTICE: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here

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;
}
developer/sdksamples/curvereverse.txt ยท Last modified: 2015/09/14 (external edit)