Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:curvereverse [2015/09/14] (current)
Line 1: Line 1:
 +====== 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 [[developer:​rhinocommonsamples:​curvereverse|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:
 +
 +  - Get the object.
 +  - Make a copy of it.
 +  - Modify the copy.
 +  - Replace the original object with the copy.
 +The following code sample demonstrates how to reverse the direction of one or more curves.
 +
 +===== C# =====
 +<code 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;​
 +}
 +
 +</​code>​
 +
 +
 +{{tag>​Developer dotnet}}
  
developer/sdksamples/curvereverse.txt ยท Last modified: 2015/09/14 (external edit)