NEW: Welcome to the Rhino 6 version of this page! Looking for the older Rhino 5 version?

Reverse Curve

Demonstrates how to reverse the direction of user-specified curves.

partial class Examples
{
  public static Result ReverseCurve(RhinoDoc doc)
  {
    ObjRef[] obj_refs;
    var rc = RhinoGet.GetMultipleObjects("Select curves to reverse", true, ObjectType.Curve, out obj_refs);
    if (rc != Result.Success)
      return rc;

    foreach (var obj_ref in obj_refs)
    {
      var curve_copy = obj_ref.Curve().DuplicateCurve();
      if (curve_copy != null)
      {
        curve_copy.Reverse();
        doc.Objects.Replace(obj_ref, curve_copy);
      }
    }
    return Result.Success;
  }
}
Partial Friend Class Examples
  Public Shared Function ReverseCurve(ByVal doc As RhinoDoc) As Result
	Dim obj_refs() As ObjRef = Nothing
	Dim rc = RhinoGet.GetMultipleObjects("Select curves to reverse", True, ObjectType.Curve, obj_refs)
	If rc IsNot Result.Success Then
	  Return rc
	End If

	For Each obj_ref In obj_refs
	  Dim curve_copy = obj_ref.Curve().DuplicateCurve()
	  If curve_copy IsNot Nothing Then
		curve_copy.Reverse()
		doc.Objects.Replace(obj_ref, curve_copy)
	  End If
	Next obj_ref
	Return Result.Success
  End Function
End Class
import rhinoscriptsyntax as rs
from scriptcontext import *
import Rhino

def ReverseCurves():
    crvs = rs.GetObjects("Select curves to reverse", rs.filter.curve)
    if not crvs: return

    for crvid in crvs:
        crv = rs.coercecurve(crvid)
        if not crv: continue
        dup = crv.DuplicateCurve()
        if dup:
            dup.Reverse()
        doc.Objects.Replace(crvid, dup)

if __name__ == "__main__":
    ReverseCurves()