GetObjectSubObjectSelect Property |
Namespace: Rhino.Input.Custom
partial class Examples { public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc) { // Select objects to orient Rhino.Input.Custom.GetObject go = new 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 Rhino.Input.Custom.GetPoint gp = new 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 Rhino.Display.RhinoView view = gp.View(); if (view == null) { view = doc.Views.ActiveView; if (view == null) return Rhino.Commands.Result.Failure; } Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane(); source_plane.Origin = gp.Point(); // Surface to orient on Rhino.Input.Custom.GetObject gs = new 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(); Rhino.DocObjects.ObjRef objref = gs.Object(0); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) return Rhino.Commands.Result.Failure; // get selected surface (face) Rhino.Geometry.Surface surface = objref.Surface(); if (surface == null) return Rhino.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 Rhino.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 transformation Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane); // Do the transformation. In this example, we will copy the original objects const bool 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; } }
import Rhino import scriptcontext import System.Guid def OrientOnSrf(): # 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() if not view: view = doc.Views.ActiveView if not view: return Rhino.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() if not obj: return Rhino.Commands.Result.Failure # get selected surface (face) surface = objref.Surface() if not surface: return Rhino.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 = False for i in range(go.ObjectCount): rhobj = go.Object(i) scriptcontext.doc.Objects.Transform(rhobj, xform, delete_original) scriptcontext.doc.Views.Redraw() rc = Rhino.Commands.Result.Success return rc if __name__=="__main__": OrientOnSrf()