Site Tools


Sample: Offset a Curve

C#

public class OffsetCurveCommand : Command
{
  public override string EnglishName { get { return "csOffsetCurve"; } }
 
  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
    ObjRef obj_ref;
    var rs = RhinoGet.GetOneObject(
      "Select Curve", false, ObjectType.Curve, out obj_ref);
    if (rs != Result.Success)
      return rs;
    var curve = obj_ref.Curve();
    if (curve == null)
      return Result.Nothing;
 
    Point3d point;
    rs = RhinoGet.GetPoint("Select Side", false, out point);
    if (rs != Result.Success)
      return rs;
    if (point == Point3d.Unset)
      return Result.Nothing;
 
    var curves = curve.Offset(point, Vector3d.ZAxis, 1.0, 
      doc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.None);
 
    foreach (var offset_curve in curves)
      doc.Objects.AddCurve(offset_curve);
 
    doc.Views.Redraw();
    return Result.Success;
  }
}

VB.NET

Public Class OffsetCurveCommand
  Inherits Command
  Public Overrides ReadOnly Property EnglishName() As String
    Get
      Return "vbOffsetCurve"
    End Get
  End Property
 
  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
    Dim obj_ref As ObjRef
    Dim rs = RhinoGet.GetOneObject("Select Curve", False, ObjectType.Curve, obj_ref)
    If rs <> Result.Success Then
      Return rs
    End If
    Dim curve = obj_ref.Curve()
    If curve Is Nothing Then
      Return Result.[Nothing]
    End If
 
    Dim point As Point3d
    rs = RhinoGet.GetPoint("Select Side", False, point)
    If rs <> Result.Success Then
      Return rs
    End If
    If point = Point3d.Unset Then
      Return Result.[Nothing]
    End If
 
    Dim curves = curve.Offset(point, Vector3d.ZAxis, 1.0, doc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.None)
 
    For Each offset_curve As Curve In curves
      doc.Objects.AddCurve(offset_curve)
    Next
 
    doc.Views.Redraw()
    Return Result.Success
  End Function
End Class
d Namespace

Python

from Rhino import *
from Rhino.DocObjects import *
from Rhino.Geometry import *
from Rhino.Input import *
from Rhino.Commands import *
from scriptcontext import doc
import rhinoscriptsyntax as rs
 
def RunCommand():
  rs, obj_ref = RhinoGet.GetOneObject("Select Curve", False, ObjectType.Curve)
  if rs <> Result.Success:
    return rs
  curve = obj_ref.Curve()
  if curve == None:
    return Result.Nothing
 
  rs, point = RhinoGet.GetPoint("Select Side", False)
  if rs <> Result.Success:
    return rs
  if point == Point3d.Unset:
    return Result.Nothing
 
  curves = curve.Offset(point, Vector3d.ZAxis, 1.0, 
    doc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.None)
 
  for offset_curve in curves:
    doc.Objects.AddCurve(offset_curve)
 
  doc.Views.Redraw()
  return Result.Success
 
if __name__ == "__main__":
  RunCommand()
developer/rhinocommonsamples/offsetcurve.txt ยท Last modified: 2015/09/14 (external edit)