usingSystem;partialclassExamples{publicstaticRhino.Commands.ResultConstrainedCopy(Rhino.RhinoDoc doc){// Get a single planar closed curvevar go =newRhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select curve");
go.GeometryFilter=Rhino.DocObjects.ObjectType.Curve;
go.GeometryAttributeFilter=Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
go.Get();if( go.CommandResult()!=Rhino.Commands.Result.Success)return go.CommandResult();var objref = go.Object(0);var base_curve = objref.Curve();var first_point = objref.SelectionPoint();if( base_curve==null||!first_point.IsValid)returnRhino.Commands.Result.Cancel;Rhino.Geometry.Plane plane;if(!base_curve.TryGetPlane(out plane))returnRhino.Commands.Result.Cancel;// Get a point constrained to a line passing through the initial selection// point and parallel to the plane's normalvar gp =newRhino.Input.Custom.GetPoint();
gp.SetCommandPrompt("Offset point");
gp.DrawLineFromPoint(first_point,true);var line =newRhino.Geometry.Line(first_point, first_point+plane.Normal);
gp.Constrain(line);
gp.Get();if( gp.CommandResult()!=Rhino.Commands.Result.Success)return gp.CommandResult();var second_point = gp.Point();Rhino.Geometry.Vector3d vec = second_point - first_point;if( vec.Length>0.001){var xf =Rhino.Geometry.Transform.Translation(vec);Guid id = doc.Objects.Transform(objref, xf,false);if( id!=Guid.Empty){
doc.Views.Redraw();returnRhino.Commands.Result.Success;}}returnRhino.Commands.Result.Cancel;}}
importRhinoimport scriptcontext
defconstrainedcopy():#get a single closed curve
go =Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select curve")
go.GeometryFilter=Rhino.DocObjects.ObjectType.Curve
go.GeometryAttributeFilter=Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve
go.Get()if go.CommandResult()!=Rhino.Commands.Result.Success:return
objref = go.Object(0)
base_curve = objref.Curve()
first_point = objref.SelectionPoint()ifnot base_curve ornot first_point.IsValid:return
isplanar, plane = base_curve.TryGetPlane()ifnot isplanar:return
gp =Rhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("Offset point")
gp.DrawLineFromPoint(first_point,True)
line =Rhino.Geometry.Line(first_point, first_point + plane.Normal)
gp.Constrain(line)
gp.Get()if gp.CommandResult()!=Rhino.Commands.Result.Success:return
second_point = gp.Point()
vec = second_point - first_point
if vec.Length>0.001:
xf =Rhino.Geometry.Transform.Translation(vec)
id = scriptcontext.doc.Objects.Transform(objref, xf,False)
scriptcontext.doc.Views.Redraw()return id
if __name__=="__main__":constrainedcopy()
PartialClassExamplesPublicSharedFunctionConstrainedCopy(doc AsRhino.RhinoDoc)AsRhino.Commands.Result' Get a single planar closed curveDim go =NewRhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select curve")
go.GeometryFilter=Rhino.DocObjects.ObjectType.Curve
go.GeometryAttributeFilter=Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve
go.Get()If go.CommandResult()<>Rhino.Commands.Result.SuccessThenReturn go.CommandResult()EndIfDim objref = go.Object(0)Dim base_curve = objref.Curve()Dim first_point = objref.SelectionPoint()If base_curve IsNothingOrElseNot first_point.IsValidThenReturnRhino.Commands.Result.CancelEndIfDim plane AsRhino.Geometry.PlaneIfNot base_curve.TryGetPlane(plane)ThenReturnRhino.Commands.Result.CancelEndIf' Get a point constrained to a line passing through the initial selection' point and parallel to the plane's normalDim gp =NewRhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("Offset point")
gp.DrawLineFromPoint(first_point,True)Dim line =NewRhino.Geometry.Line(first_point, first_point + plane.Normal)
gp.Constrain(line)
gp.Get()If gp.CommandResult()<>Rhino.Commands.Result.SuccessThenReturn gp.CommandResult()EndIfDim second_point = gp.Point()Dim vec AsRhino.Geometry.Vector3d= second_point - first_point
If vec.Length>0.001ThenDim xf =Rhino.Geometry.Transform.Translation(vec)Dim id AsGuid= doc.Objects.Transform(objref, xf,False)If id <>Guid.EmptyThen
doc.Views.Redraw()ReturnRhino.Commands.Result.SuccessEndIfEndIfReturnRhino.Commands.Result.CancelEndFunctionEndClass