partialclassExamples{publicstaticRhino.Commands.ResultOrientOnSrf(Rhino.RhinoDoc doc){// Select objects to orientRhino.Input.Custom.GetObject go =newRhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select objects to orient");
go.SubObjectSelect=false;
go.GroupSelect=true;
go.GetMultiple(1,0);if(go.CommandResult()!=Rhino.Commands.Result.Success)return go.CommandResult();// Point to orient fromRhino.Input.Custom.GetPoint gp =newRhino.Input.Custom.GetPoint();
gp.SetCommandPrompt("Point to orient from");
gp.Get();if(gp.CommandResult()!=Rhino.Commands.Result.Success)return gp.CommandResult();// Define source planeRhino.Display.RhinoView view = gp.View();if(view ==null){
view = doc.Views.ActiveView;if(view ==null)returnRhino.Commands.Result.Failure;}Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
source_plane.Origin= gp.Point();// Surface to orient onRhino.Input.Custom.GetObject gs =newRhino.Input.Custom.GetObject();
gs.SetCommandPrompt("Surface to orient on");
gs.GeometryFilter=Rhino.DocObjects.ObjectType.Surface;
gs.SubObjectSelect=true;
gs.DeselectAllBeforePostSelect=false;
gs.OneByOnePostSelect=true;
gs.Get();if(gs.CommandResult()!=Rhino.Commands.Result.Success)return gs.CommandResult();Rhino.DocObjects.ObjRef objref = gs.Object(0);// get selected surface objectRhino.DocObjects.RhinoObject obj = objref.Object();if(obj ==null)returnRhino.Commands.Result.Failure;// get selected surface (face)Rhino.Geometry.Surface surface = objref.Surface();if(surface ==null)returnRhino.Commands.Result.Failure;// Unselect surface
obj.Select(false);// Point on surface to orient to
gp.SetCommandPrompt("Point on surface to orient to");
gp.Constrain(surface,false);
gp.Get();if(gp.CommandResult()!=Rhino.Commands.Result.Success)return gp.CommandResult();// Do transformationRhino.Commands.Result rc =Rhino.Commands.Result.Failure;double u, v;if(surface.ClosestPoint(gp.Point(),out u,out v)){Rhino.Geometry.Plane target_plane;if(surface.FrameAt(u, v,out target_plane)){// Build transformationRhino.Geometry.Transform xform =Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);// Do the transformation. In this example, we will copy the original objectsconstbool delete_original =false;for(int i =0; i < go.ObjectCount; i++)
doc.Objects.Transform(go.Object(i), xform, delete_original);
doc.Views.Redraw();
rc =Rhino.Commands.Result.Success;}}return rc;}}
importRhinoimport scriptcontext
importSystem.GuiddefOrientOnSrf():# Select objects to orient
go =Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects to orient")
go.SubObjectSelect=False
go.GroupSelect=True
go.GetMultiple(1,0)if go.CommandResult()!=Rhino.Commands.Result.Success:return go.CommandResult()# Point to orient from
gp =Rhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("Point to orient from")
gp.Get()if gp.CommandResult()!=Rhino.Commands.Result.Success:return gp.CommandResult()# Define source plane
view = gp.View()ifnot view:
view = doc.Views.ActiveViewifnot view:returnRhino.Commands.Result.Failure
source_plane = view.ActiveViewport.ConstructionPlane()
source_plane.Origin= gp.Point()# Surface to orient on
gs =Rhino.Input.Custom.GetObject()
gs.SetCommandPrompt("Surface to orient on")
gs.GeometryFilter=Rhino.DocObjects.ObjectType.Surface
gs.SubObjectSelect=True
gs.DeselectAllBeforePostSelect=False
gs.OneByOnePostSelect=True
gs.Get()if gs.CommandResult()!=Rhino.Commands.Result.Success:return gs.CommandResult()
objref = gs.Object(0)# get selected surface object
obj = objref.Object()ifnot obj:returnRhino.Commands.Result.Failure# get selected surface (face)
surface = objref.Surface()ifnot surface:returnRhino.Commands.Result.Failure# Unselect surface
obj.Select(False)# Point on surface to orient to
gp.SetCommandPrompt("Point on surface to orient to")
gp.Constrain(surface,False)
gp.Get()if gp.CommandResult()!=Rhino.Commands.Result.Success:return gp.CommandResult()# Do transformation
rc =Rhino.Commands.Result.Failure
getrc, u, v = surface.ClosestPoint(gp.Point())if getrc:
getrc, target_plane = surface.FrameAt(u,v)if getrc:# Build transformation
xform =Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane)# Do the transformation. In this example, we will copy the original objects
delete_original =Falsefor i inrange(go.ObjectCount):
rhobj = go.Object(i)
scriptcontext.doc.Objects.Transform(rhobj, xform, delete_original)
scriptcontext.doc.Views.Redraw()
rc =Rhino.Commands.Result.Successreturn rc
if __name__=="__main__":OrientOnSrf()
PartialClassExamplesPublicSharedFunctionOrientOnSrf(ByVal doc AsRhino.RhinoDoc)AsRhino.Commands.Result' Select objects to orientDim go AsNewRhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects to orient")
go.SubObjectSelect=False
go.GroupSelect=True
go.GetMultiple(1,0)If go.CommandResult()<>Rhino.Commands.Result.SuccessThenReturn go.CommandResult()EndIf' Point to orient fromDim gp AsNewRhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("Point to orient from")
gp.Get()If gp.CommandResult()<>Rhino.Commands.Result.SuccessThenReturn gp.CommandResult()EndIf' Define source planeDim view AsRhino.Display.RhinoView= gp.View()If view IsNothingThen
view = doc.Views.ActiveViewIf view IsNothingThenReturnRhino.Commands.Result.FailureEndIfEndIfDim source_plane AsRhino.Geometry.Plane= view.ActiveViewport.ConstructionPlane()
source_plane.Origin= gp.Point()' Surface to orient onDim gs AsNewRhino.Input.Custom.GetObject()
gs.SetCommandPrompt("Surface to orient on")
gs.GeometryFilter=Rhino.DocObjects.ObjectType.Surface
gs.SubObjectSelect=True
gs.DeselectAllBeforePostSelect=False
gs.OneByOnePostSelect=True
gs.Get()If gs.CommandResult()<>Rhino.Commands.Result.SuccessThenReturn gs.CommandResult()EndIfDim objref AsRhino.DocObjects.ObjRef= gs.[Object](0)' get selected surface objectDim obj AsRhino.DocObjects.RhinoObject= objref.[Object]()If obj IsNothingThenReturnRhino.Commands.Result.FailureEndIf' get selected surface (face)Dim surface AsRhino.Geometry.Surface= objref.Surface()If surface IsNothingThenReturnRhino.Commands.Result.FailureEndIf' Unselect surface
obj.[Select](False)' Point on surface to orient to
gp.SetCommandPrompt("Point on surface to orient to")
gp.Constrain(surface,False)
gp.Get()If gp.CommandResult()<>Rhino.Commands.Result.SuccessThenReturn gp.CommandResult()EndIf' Do transformationDim rc AsRhino.Commands.Result=Rhino.Commands.Result.FailureDim u AsDouble, v AsDoubleIf surface.ClosestPoint(gp.Point(), u, v)ThenDim target_plane AsRhino.Geometry.PlaneIf surface.FrameAt(u, v, target_plane)Then' Build transformationDim xform AsRhino.Geometry.Transform=Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane)' Do the transformation. In this example, we will copy the original objectsConst delete_original AsBoolean=FalseFor i AsInteger=0To go.ObjectCount-1
doc.Objects.Transform(go.[Object](i), xform, delete_original)Next
doc.Views.Redraw()
rc =Rhino.Commands.Result.SuccessEndIfEndIfReturn rc
EndFunctionEndClass