public static Rhino.Commands.Result ConstrainedCopy(Rhino.RhinoDoc doc) { // Get a single planar closed curve var go = new 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(go.CommandResult()); } var objref = go.Object(0); var base_curve = objref.Curve(); var first_point = objref.SelectionPoint(); if (base_curve == null || !first_point.IsValid) { return(Rhino.Commands.Result.Cancel); } Rhino.Geometry.Plane plane; if (!base_curve.TryGetPlane(out plane)) { return(Rhino.Commands.Result.Cancel); } // Get a point constrained to a line passing through the initial selection // point and parallel to the plane's normal var gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Offset point"); gp.DrawLineFromPoint(first_point, true); var line = new Rhino.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(); return(Rhino.Commands.Result.Success); } } return(Rhino.Commands.Result.Cancel); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ObjRef obj_ref; var rc = RhinoGet.GetOneObject("Select surface for curvature measurement", true, ObjectType.Surface, out obj_ref); if (rc != Result.Success) return rc; var surface = obj_ref.Surface(); var gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Select point on surface for curvature measurement"); gp.Constrain(surface, false); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var point_on_surface = gp.Point(); double u, v; if (!surface.ClosestPoint(point_on_surface, out u, out v)) return Result.Failure; var surface_curvature = surface.CurvatureAt(u, v); if (surface_curvature == null) return Result.Failure; RhinoApp.WriteLine("Surface curvature evaluation at parameter: ({0}, {1})", u, v); RhinoApp.WriteLine(" 3-D Point: ({0}, {1}, {2})", surface_curvature.Point.X, surface_curvature.Point.Y, surface_curvature.Point.Z); RhinoApp.WriteLine(" 3-D Normal: ({0}, {1}, {2})", surface_curvature.Normal.X, surface_curvature.Normal.Y, surface_curvature.Normal.Z); RhinoApp.WriteLine(string.Format(" Maximum principal curvature: {0} ({1}, {2}, {3})", surface_curvature.Kappa(0), surface_curvature.Direction(0).X, surface_curvature.Direction(0).Y, surface_curvature.Direction(0).Z)); RhinoApp.WriteLine(string.Format(" Minimum principal curvature: {0} ({1}, {2}, {3})", surface_curvature.Kappa(1), surface_curvature.Direction(1).X, surface_curvature.Direction(1).Y, surface_curvature.Direction(1).Z)); RhinoApp.WriteLine(" Gaussian curvature: {0}", surface_curvature.Gaussian); RhinoApp.WriteLine(" Mean curvature: {0}", surface_curvature.Mean); return Result.Success; }
public static Rhino.Commands.Result InsertKnot(Rhino.RhinoDoc doc) { const ObjectType filter = Rhino.DocObjects.ObjectType.Curve; Rhino.DocObjects.ObjRef objref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select curve for knot insertion", false, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Geometry.Curve curve = objref.Curve(); if (null == curve) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.NurbsCurve nurb = curve.ToNurbsCurve(); if (null == nurb) { return(Rhino.Commands.Result.Failure); } Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Point on curve to add knot"); gp.Constrain(nurb, false); gp.Get(); if (gp.CommandResult() == Rhino.Commands.Result.Success) { double t; Rhino.Geometry.Curve crv = gp.PointOnCurve(out t); if (crv != null && nurb.Knots.InsertKnot(t)) { doc.Objects.Replace(objref, nurb); doc.Views.Redraw(); } } return(Rhino.Commands.Result.Success); }
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); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { Rhino.DocObjects.ObjRef objref; var rc = Rhino.Input.RhinoGet.GetOneObject("Select object", true, Rhino.DocObjects.ObjectType.AnyObject, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } rc = Rhino.Input.RhinoGet.GetPoint("Start point", false, out m_point_start); if (rc != Rhino.Commands.Result.Success) { return(rc); } var obj = objref.Object(); if (obj == null) { return(Rhino.Commands.Result.Failure); } // create an instance of a GetPoint class and add a delegate // for the DynamicDraw event var gp = new Rhino.Input.Custom.GetPoint(); gp.DrawLineFromPoint(m_point_start, true); var optdouble = new Rhino.Input.Custom.OptionDouble(m_distance); bool constrain = false; var optconstrain = new Rhino.Input.Custom.OptionToggle(constrain, "Off", "On"); gp.AddOptionDouble("Distance", ref optdouble); gp.AddOptionToggle("Constrain", ref optconstrain); gp.DynamicDraw += ArrayByDistanceDraw; gp.Tag = obj; while (gp.Get() == Rhino.Input.GetResult.Option) { m_distance = optdouble.CurrentValue; if (constrain != optconstrain.CurrentValue) { constrain = optconstrain.CurrentValue; if (constrain) { var gp2 = new Rhino.Input.Custom.GetPoint(); gp2.DrawLineFromPoint(m_point_start, true); gp2.SetCommandPrompt("Second point on constraint line"); if (gp2.Get() == Rhino.Input.GetResult.Point) { gp.Constrain(m_point_start, gp2.Point()); } else { gp.ClearCommandOptions(); optconstrain.CurrentValue = false; constrain = false; gp.AddOptionDouble("Distance", ref optdouble); gp.AddOptionToggle("Constrain", ref optconstrain); } } else { gp.ClearConstraints(); } } } if (gp.CommandResult() == Rhino.Commands.Result.Success) { m_distance = optdouble.CurrentValue; var pt = gp.Point(); var vec = pt - m_point_start; double length = vec.Length; vec.Unitize(); int count = (int)(length / m_distance); for (int i = 1; i < count; i++) { var translate = vec * (i * m_distance); var xf = Rhino.Geometry.Transform.Translation(translate); doc.Objects.Transform(obj, xf, false); } doc.Views.Redraw(); } return(gp.CommandResult()); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.DocObjects.ObjRef obj_ref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select curve", false, Rhino.DocObjects.ObjectType.Curve, out obj_ref); if (rc != Result.Success) { return(rc); } Rhino.DocObjects.RhinoObject obj = obj_ref.Object(); if (null == obj) { return(Result.Failure); } obj_ref.Object().Select(false); doc.Views.Redraw(); Rhino.Geometry.Curve crv = obj_ref.Curve(); if (null == crv) { return(Result.Failure); } Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("First point on curve"); gp.Constrain(crv, false); gp.Get(); rc = gp.CommandResult(); if (rc != Result.Success) { return(rc); } double t0 = Rhino.RhinoMath.UnsetValue; if (null == gp.PointOnCurve(out t0)) { return(Result.Failure); } gp.SetCommandPrompt("Second point on curve"); gp.Get(); rc = gp.CommandResult(); if (rc != Result.Success) { return(rc); } double t1 = Rhino.RhinoMath.UnsetValue; if (null == gp.PointOnCurve(out t1)) { return(Result.Failure); } if (System.Math.Abs(t1 - t0) < Rhino.RhinoMath.ZeroTolerance) { return(Result.Failure); } if (crv.IsClosed || (!crv.IsClosed && t0 > t1)) { double t = t0; t0 = t1; t1 = t; } Rhino.Geometry.Interval range = new Rhino.Geometry.Interval(t0, t1); Rhino.Geometry.Curve subcrv = crv.Trim(range); if (null != subcrv) { System.Guid id = doc.Objects.Add(subcrv); obj = doc.Objects.Find(id); if (null != obj) { obj.Select(true); } } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ObjRef obj_ref; var rc = RhinoGet.GetOneObject("Select surface for curvature measurement", true, ObjectType.Surface, out obj_ref); if (rc != Result.Success) { return(rc); } var surface = obj_ref.Surface(); var gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Select point on surface for curvature measurement"); gp.Constrain(surface, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var point_on_surface = gp.Point(); double u, v; if (!surface.ClosestPoint(point_on_surface, out u, out v)) { return(Result.Failure); } var surface_curvature = surface.CurvatureAt(u, v); if (surface_curvature == null) { return(Result.Failure); } RhinoApp.WriteLine("Surface curvature evaluation at parameter: ({0}, {1})", u, v); RhinoApp.WriteLine(" 3-D Point: ({0}, {1}, {2})", surface_curvature.Point.X, surface_curvature.Point.Y, surface_curvature.Point.Z); RhinoApp.WriteLine(" 3-D Normal: ({0}, {1}, {2})", surface_curvature.Normal.X, surface_curvature.Normal.Y, surface_curvature.Normal.Z); RhinoApp.WriteLine(string.Format(" Maximum principal curvature: {0} ({1}, {2}, {3})", surface_curvature.Kappa(0), surface_curvature.Direction(0).X, surface_curvature.Direction(0).Y, surface_curvature.Direction(0).Z)); RhinoApp.WriteLine(string.Format(" Minimum principal curvature: {0} ({1}, {2}, {3})", surface_curvature.Kappa(1), surface_curvature.Direction(1).X, surface_curvature.Direction(1).Y, surface_curvature.Direction(1).Z)); RhinoApp.WriteLine(" Gaussian curvature: {0}", surface_curvature.Gaussian); RhinoApp.WriteLine(" Mean curvature: {0}", surface_curvature.Mean); return(Result.Success); }
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; }