public static Result PickPoint(RhinoDoc doc) { // this creates a point where the mouse is clicked. var gp = new GetPoint(); gp.SetCommandPrompt("Click for new point"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var point3d = gp.Point(); doc.Objects.AddPoint(point3d); doc.Views.Redraw(); // selects a point that already exists ObjRef obj_ref; var rc = RhinoGet.GetOneObject("Select point", false, ObjectType.Point, out obj_ref); if (rc != Result.Success) return rc; var point = obj_ref.Point(); RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); doc.Objects.UnselectAll(); // selects multiple points that already exist ObjRef[] obj_refs; rc = RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs); if (rc != Result.Success) return rc; foreach (var o_ref in obj_refs) { point = o_ref.Point(); RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); } doc.Objects.UnselectAll(); // also selects a point that already exists. // Used when RhinoGet doesn't provide enough control var go = new GetObject(); go.SetCommandPrompt("Select point"); go.GeometryFilter = ObjectType.Point; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) return go.CommandResult(); foreach (var o_ref in go.Objects()) { point = o_ref.Point(); if (point != null) RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); } doc.Views.Redraw(); return Result.Success; }
public static Rhino.Commands.Result AddLine(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Start of line"); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); Rhino.Geometry.Point3d pt_start = gp.Point(); gp.SetCommandPrompt("End of line"); gp.SetBasePoint(pt_start, false); gp.DrawLineFromPoint(pt_start, true); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); Rhino.Geometry.Point3d pt_end = gp.Point(); Rhino.Geometry.Vector3d v = pt_end - pt_start; if (v.IsTiny(Rhino.RhinoMath.ZeroTolerance)) return Rhino.Commands.Result.Nothing; if (doc.Objects.AddLine(pt_start, pt_end) != Guid.Empty) { doc.Views.Redraw(); return Rhino.Commands.Result.Success; } return Rhino.Commands.Result.Failure; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.DocObjects.ObjRef objref; var rc = RhinoGet.GetOneObject("Select curve", true, ObjectType.Curve,out objref); if(rc!= Result.Success) return rc; var curve = objref.Curve(); if( curve==null ) return Result.Failure; var gp = new GetPoint(); gp.SetCommandPrompt("Pick a location on the curve"); gp.Constrain(curve, false); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var point = gp.Point(); double closest_point_param; if (curve.ClosestPoint(point, out closest_point_param)) { RhinoApp.WriteLine("point: ({0}), parameter: {1}", point, closest_point_param); doc.Objects.AddPoint(point); doc.Views.Redraw(); } return Result.Success; }
public static Result Ortho(RhinoDoc doc) { var gp = new GetPoint(); gp.SetCommandPrompt("Start of line"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var start_point = gp.Point(); var original_ortho = ModelAidSettings.Ortho; if (!original_ortho) ModelAidSettings.Ortho = true; gp.SetCommandPrompt("End of line"); gp.SetBasePoint(start_point, false); gp.DrawLineFromPoint(start_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var end_point = gp.Point(); if (ModelAidSettings.Ortho != original_ortho) ModelAidSettings.Ortho = original_ortho; doc.Objects.AddLine(start_point, end_point); doc.Views.Redraw(); return Result.Success; }
public static Result GetPointDynamicDraw(RhinoDoc doc) { var gp = new GetPoint(); gp.SetCommandPrompt("Center point"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var center_point = gp.Point(); if (center_point == Point3d.Unset) return Result.Failure; var gcp = new GetCircleRadiusPoint(center_point); gcp.SetCommandPrompt("Radius"); gcp.ConstrainToConstructionPlane(false); gcp.SetBasePoint(center_point, true); gcp.DrawLineFromPoint(center_point, true); gcp.Get(); if (gcp.CommandResult() != Result.Success) return gcp.CommandResult(); var radius = center_point.DistanceTo(gcp.Point()); var cplane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); doc.Objects.AddCircle(new Circle(cplane, center_point, radius)); doc.Views.Redraw(); return Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ObjRef[] obj_refs; var rc = RhinoGet.GetMultipleObjects("Select points to move", false, ObjectType.Point, out obj_refs); if (rc != Result.Success || obj_refs == null) return rc; var gp = new GetPoint(); gp.SetCommandPrompt("Point to move from"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var start_point = gp.Point(); gp.SetCommandPrompt("Point to move to"); gp.SetBasePoint(start_point, false); gp.DrawLineFromPoint(start_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var end_point = gp.Point(); var xform = Transform.Translation(end_point - start_point); foreach (var obj_ref in obj_refs) { doc.Objects.Transform(obj_ref, xform, true); } doc.Views.Redraw(); return Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var filter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh; ObjRef[] obj_refs; var rc = RhinoGet.GetMultipleObjects("Select objects to contour", false, filter, out obj_refs); if (rc != Result.Success) return rc; var gp = new GetPoint(); gp.SetCommandPrompt("Contour plane base point"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var base_point = gp.Point(); gp.DrawLineFromPoint(base_point, true); gp.SetCommandPrompt("Direction perpendicular to contour planes"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var end_point = gp.Point(); if (base_point.DistanceTo(end_point) < RhinoMath.ZeroTolerance) return Result.Nothing; double distance = 1.0; rc = RhinoGet.GetNumber("Distance between contours", false, ref distance); if (rc != Result.Success) return rc; var interval = Math.Abs(distance); Curve[] curves = null; foreach (var obj_ref in obj_refs) { var geometry = obj_ref.Geometry(); if (geometry == null) return Result.Failure; if (geometry is Brep) { curves = Brep.CreateContourCurves(geometry as Brep, base_point, end_point, interval); } else { curves = Mesh.CreateContourCurves(geometry as Mesh, base_point, end_point, interval); } foreach (var curve in curves) { var curve_object_id = doc.Objects.AddCurve(curve); doc.Objects.Select(curve_object_id); } } if (curves != null) doc.Views.Redraw(); return Result.Success; }
public static Rhino.Commands.Result AddBackgroundBitmap(Rhino.RhinoDoc doc) { Rhino.RhinoApp.WriteLine ("hey"); // Allow the user to select a bitmap file Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog(); fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"; if (!fd.ShowDialog()) return Rhino.Commands.Result.Cancel; // Verify the file that was selected System.Drawing.Image image; try { image = System.Drawing.Image.FromFile(fd.FileName); } catch (Exception) { return Rhino.Commands.Result.Failure; } // Allow the user to pick the bitmap origin Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Bitmap Origin"); gp.ConstrainToConstructionPlane(true); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); // Get the view that the point was picked in. // This will be the view that the bitmap appears in. Rhino.Display.RhinoView view = gp.View(); if (view == null) { view = doc.Views.ActiveView; if (view == null) return Rhino.Commands.Result.Failure; } // Allow the user to specify the bitmap with in model units Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber(); gn.SetCommandPrompt("Bitmap width"); gn.SetLowerLimit(1.0, false); gn.Get(); if (gn.CommandResult() != Rhino.Commands.Result.Success) return gn.CommandResult(); // Cook up some scale factors double w = gn.Number(); double image_width = image.Width; double image_height = image.Height; double h = w * (image_height / image_width); Rhino.Geometry.Plane plane = view.ActiveViewport.ConstructionPlane(); plane.Origin = gp.Point(); view.ActiveViewport.SetTraceImage(fd.FileName, plane, w, h, false, false); view.Redraw(); return Rhino.Commands.Result.Success; }
public static Result PrincipalCurvature(RhinoDoc doc) { 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; }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { var conduit = new PointsConduit(m_conduit_points); conduit.Enabled = true; var gp = new Rhino.Input.Custom.GetPoint(); while (true) { gp.SetCommandPrompt("click location to create point. (<ESC> exit)"); gp.AcceptNothing(true); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) break; m_conduit_points.Add(new ConduitPoint(gp.Point())); doc.Views.Redraw(); } var gcp = new GetConduitPoint(m_conduit_points); while (true) { gcp.SetCommandPrompt("select conduit point. (<ESC> to exit)"); gcp.AcceptNothing(true); gcp.Get(true); doc.Views.Redraw(); if (gcp.CommandResult() != Rhino.Commands.Result.Success) break; } return Rhino.Commands.Result.Success; }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { // TODO: start here modifying the behaviour of your command. // --- RhinoApp.WriteLine ("The {0} command will add a line right now.", EnglishName); Point3d pt0; using (GetPoint getPointAction = new GetPoint ()) { getPointAction.SetCommandPrompt ("Please select the start point"); if (getPointAction.Get () != GetResult.Point) { RhinoApp.WriteLine ("No start point was selected."); return getPointAction.CommandResult (); } pt0 = getPointAction.Point (); } Point3d pt1; using (GetPoint getPointAction = new GetPoint ()) { getPointAction.SetCommandPrompt ("Please select the end point"); getPointAction.SetBasePoint (pt0, true); getPointAction.DrawLineFromPoint (pt0, true); if (getPointAction.Get () != GetResult.Point) { RhinoApp.WriteLine ("No end point was selected."); return getPointAction.CommandResult (); } pt1 = getPointAction.Point (); } doc.Objects.AddLine (pt0, pt1); doc.Views.Redraw (); RhinoApp.WriteLine ("The {0} command added one line to the document.", EnglishName); return Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gp = new GetPoint(); gp.SetCommandPrompt("Start:"); if (gp.Get() != GetResult.Point) { RhinoApp.WriteLine("No point selected."); return gp.CommandResult(); } var location = gp.Point(); var dialog = new BBTextDialog(); if (dialog.ShowDialog()!= true) return Result.Cancel; var typeWriter = dialog.Bold ? Typewriter.Bold : Typewriter.Regular; var x = doc.Views.ActiveView.ActiveViewport.CameraX; var y = doc.Views.ActiveView.ActiveViewport.CameraY; var unitX = x * dialog.Size; var unitY = y * dialog.Size; var curves = typeWriter.Write(dialog.Text, location, unitX, unitY, dialog.HAlign, dialog.VAlign); doc.Groups.Add(curves.Select(curve => doc.Objects.AddCurve(curve))); doc.Views.Redraw(); 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 CommandLineOptions(Rhino.RhinoDoc doc) { // For this example we will use a GetPoint class, but all of the custom // "Get" classes support command line options. Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("GetPoint with options"); // set up the options Rhino.Input.Custom.OptionInteger intOption = new Rhino.Input.Custom.OptionInteger(1, 1, 99); Rhino.Input.Custom.OptionDouble dblOption = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9); Rhino.Input.Custom.OptionToggle boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On"); string[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" }; gp.AddOptionInteger("Integer", ref intOption); gp.AddOptionDouble("Double", ref dblOption); gp.AddOptionToggle("Boolean", ref boolOption); int listIndex = 3; int opList = gp.AddOptionList("List", listValues, listIndex); while (true) { // perform the get operation. This will prompt the user to input a point, but also // allow for command line options defined above Rhino.Input.GetResult get_rc = gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); if (get_rc == Rhino.Input.GetResult.Point) { doc.Objects.AddPoint(gp.Point()); doc.Views.Redraw(); Rhino.RhinoApp.WriteLine("Command line option values are"); Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue); Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue); Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue); Rhino.RhinoApp.WriteLine(" List = {0}", listValues[listIndex]); } else if (get_rc == Rhino.Input.GetResult.Option) { if (gp.OptionIndex() == opList) listIndex = gp.Option().CurrentListOptionIndex; continue; } break; } return Rhino.Commands.Result.Success; }
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) { // select a surface var gs = new GetObject(); gs.SetCommandPrompt("select surface"); gs.GeometryFilter = ObjectType.Surface; gs.DisablePreSelect(); gs.SubObjectSelect = false; gs.Get(); if (gs.CommandResult() != Result.Success) return gs.CommandResult(); // get the selected face var face = gs.Object(0).Face(); if (face == null) return Result.Failure; // pick a point on the surface. Constain // picking to the face. var gp = new GetPoint(); gp.SetCommandPrompt("select point on surface"); gp.Constrain(face, false); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); // get the parameters of the point on the // surface that is clesest to gp.Point() double u, v; if (face.ClosestPoint(gp.Point(), out u, out v)) { var direction = face.NormalAt(u, v); if (face.OrientationIsReversed) direction.Reverse(); RhinoApp.WriteLine( string.Format( "Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})", u, v, direction.X, direction.Y, direction.Z)); } return Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gp = new GetPoint(); gp.SetCommandPrompt("Base point"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var base_point = gp.Point(); gp.SetCommandPrompt("First reference point"); gp.DrawLineFromPoint(base_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var first_point = gp.Point(); double angle_radians; var rc = RhinoGet.GetAngle("Second reference point", base_point, first_point, 0, out angle_radians); if (rc == Result.Success) RhinoApp.WriteLine("Angle = {0} degrees", RhinoMath.ToDegrees(angle_radians)); return rc; }
public static Rhino.Commands.Result AddNamedView(Rhino.RhinoDoc doc) { Rhino.Display.RhinoView view = null; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetView("Select view to adjust", out view); if (rc != Rhino.Commands.Result.Success) return rc; Rhino.Geometry.Point3d location; rc = Rhino.Input.RhinoGet.GetPoint("Camera Location", false, out location); if (rc != Rhino.Commands.Result.Success) return rc; Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Look At Location"); gp.DrawLineFromPoint(location, false); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); Rhino.Geometry.Point3d lookat = gp.Point(); string name = view.ActiveViewport.Name; rc = Rhino.Input.RhinoGet.GetString("Name", true, ref name); if (rc != Rhino.Commands.Result.Success) return rc; Rhino.Display.RhinoViewport vp = view.ActiveViewport; // save the current viewport projection vp.PushViewProjection(); vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis; vp.SetCameraLocation(location, false); vp.SetCameraDirection(lookat - location, true); vp.Name = name; doc.NamedViews.Add(name, vp.Id); view.Redraw(); return Rhino.Commands.Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Loop loop = new Loop(); loop.Run(doc); return Result.Success; // TODO: start here modifying the behaviour of your command. // --- RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the start point"); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No start point was selected."); return getPointAction.CommandResult(); } pt0 = getPointAction.Point(); } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the end point"); getPointAction.SetBasePoint(pt0, true); getPointAction.DynamicDraw += (sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No end point was selected."); return getPointAction.CommandResult(); } pt1 = getPointAction.Point(); } doc.Objects.AddLine(pt0, pt1); doc.Views.Redraw(); RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName); // --- return Result.Success; }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { var conduit = new PointsConduit(m_conduit_points); conduit.Enabled = true; var gp = new Rhino.Input.Custom.GetPoint(); while (true) { gp.SetCommandPrompt("click location to create point. (<ESC> exit)"); gp.AcceptNothing(true); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { break; } m_conduit_points.Add(new ConduitPoint(gp.Point())); doc.Views.Redraw(); } var gcp = new GetConduitPoint(m_conduit_points); while (true) { gcp.SetCommandPrompt("select conduit point. (<ESC> to exit)"); gcp.AcceptNothing(true); gcp.Get(true); doc.Views.Redraw(); if (gcp.CommandResult() != Rhino.Commands.Result.Success) { break; } } return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //pick surface to orient to or block instance to relocate GetObject gs = new Rhino.Input.Custom.GetObject(); gs.SetCommandPrompt("Surface to orient new object on or BlockInstance to move"); gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.InstanceReference; gs.SubObjectSelect = true; gs.DeselectAllBeforePostSelect = false; gs.OneByOnePostSelect = true; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } Rhino.DocObjects.ObjRef objref = gs.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } surface = objref.Surface(); //relocate block instance if (surface == null) { Rhino.DocObjects.InstanceObject instance1 = objref.Object() as Rhino.DocObjects.InstanceObject; instancePoint = instance1.InsertionPoint; double g, h; surface2.ClosestPoint(instancePoint, out g, out h); var instanceDirection = surface2.NormalAt(g, h); instancePlane = new Plane(instancePoint, instanceDirection); Rhino.Input.Custom.GetPoint gpss = new Rhino.Input.Custom.GetPoint(); gpss.SetCommandPrompt("Point on surface to orient to"); gpss.Constrain(surface2, false); gpss.DynamicDraw += RefObjDraw; gpss.Tag = instance1; gpss.Get(); if (gpss.CommandResult() != Rhino.Commands.Result.Success) { return(gpss.CommandResult()); } Point3d ptss = gpss.Point(); surface2.ClosestPoint(ptss, out g, out h); var direction1 = surface2.NormalAt(g, h); Plane pl11 = new Plane(ptss, direction1); Transform iform = Rhino.Geometry.Transform.PlaneToPlane(instancePlane, pl11); doc.Objects.Transform(instance1, iform, true); return(Result.Success); } obj.Select(false); //pick objekt to orient var copy = new Rhino.Input.Custom.OptionToggle(false, "No", "Yes"); GetObject go = new GetObject(); go.SetCommandPrompt("Select object to orient."); go.AddOptionToggle("Copy", ref copy); go.SubObjectSelect = true; go.DeselectAllBeforePostSelect = false; go.GroupSelect = true; for (; ;) { var res = go.GetMultiple(1, -1); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } if (res == GetResult.Option) { copyBol = copy.CurrentValue; continue; } if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } break; } int obCount = go.ObjectCount; string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); //create block instance and plane for instance 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()); } Vector3d vt1 = new Vector3d(0, 0, 1); Point3d pt1 = gp.Point(); sourcePlane = new Plane(pt1, vt1); Plane originPlane = new Plane(Point3d.Origin, vt1); Transform bform = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane); //block instance GeometryBase[] obj1List = new GeometryBase[obCount]; List <Brep> opList = new List <Brep>(); for (int igo = 0; igo < obCount; igo++) { Rhino.DocObjects.ObjRef objref1 = go.Object(igo); Rhino.DocObjects.RhinoObject obj1 = objref1.Object(); if (obj == null) { return(Result.Failure); } obj.Select(false); Rhino.Geometry.Brep opItem = objref1.Brep(); opList.Add(opItem); GeometryBase obj1Base = obj1.Geometry; obj1Base.Transform(bform); obj1List[igo] = obj1Base; } var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List); //get all go.Objects to .Tag Brep[] op = new Brep[obCount]; op = Brep.CreateBooleanUnion(opList, 0.01); Brep od = new Brep(); od = op[0]; var odGuid = doc.Objects.AddBrep(od); Rhino.DocObjects.ObjRef objref2 = new Rhino.DocObjects.ObjRef(odGuid); Rhino.DocObjects.RhinoObject objDrw = objref2.Object(); //orient plane to surface if (copyBol) { while (true) { Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint(); gps.SetCommandPrompt("Point on surface to orient to. Press enter when done."); gps.Constrain(surface, false); gps.AcceptNothing(true); gps.DynamicDraw += RefObjDraw; gps.Tag = objDrw; var res = gps.Get(); if (res == GetResult.Nothing) { break; } //else if (gps.CommandResult() != Rhino.Commands.Result.Success) // return gps.CommandResult(); Point3d pts = gps.Point(); double u, v; surface.ClosestPoint(pts, out u, out v); Vector3d direction = surface.NormalAt(u, v); Plane pl1 = new Plane(pts, direction); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1); doc.Objects.AddInstanceObject(orientBlock, xform); doc.Objects.Delete(objDrw); } copyBol = false; } else { Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint(); gps.SetCommandPrompt("Point on surface to orient to"); gps.Constrain(surface, false); gps.DynamicDraw += RefObjDraw; gps.Tag = objDrw; gps.Get(); if (gps.CommandResult() != Rhino.Commands.Result.Success) { return(gps.CommandResult()); } Point3d pts = gps.Point(); double u, v; surface.ClosestPoint(pts, out u, out v); Vector3d direction = surface.NormalAt(u, v); Plane pl1 = new Plane(pts, direction); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1); doc.Objects.AddInstanceObject(orientBlock, xform); doc.Objects.Delete(objDrw); } surface2 = surface; return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var primal = new PFoam(); var dual = new PFoam(); // load the foam from the geometry try { var guids = LoadData.LoadPrimalDual(out primal, out dual, out ContainerType container, false); if (primal.Cells.Count < 1) { Rhino.RhinoApp.WriteLine("Error creating dual from provided data!"); return(Result.Failure); } bool usePFDual = true; bool validDual = false; var form = primal.Edges.Where(e => e.Id > 0).Any(x => x.Faces.Count < 2); if (dual.Id == primal.Dual.Id && dual.Cells.Count >= 1) { validDual = true; //Rhino.Input.RhinoGet.GetBool("PolyFrame Dual data detected. Use stored geometry?", false, "no", "yes", ref usePFDual); } // here primal connection to dual is only established if dual is not fully reconstructed. if (validDual && !usePFDual) { var tempDualDict = new Dictionary <int, Point3d>(); if (form) { tempDualDict = primal.ComputePrimalVertices(); } else { tempDualDict = primal.ComputeDualVertices(); } foreach (var vert in dual.Vertices) { vert.Point = tempDualDict[vert.Id]; } foreach (var face in dual.Faces) { face.FaceMesh(); face.ComputeCentroid(); face.ComputeFaceNormal(); } foreach (var cell in dual.Cells) { cell.ComputeCentroid(); } dual.Centroid = PFVertex.AverageVertexes(primal.Vertices); Util.ConnectDuals(ref primal, ref dual); } else if (!validDual) { if (form) { dual = primal.CreatePrimal(); } else { dual = primal.CreateDual(); } } else if (validDual && usePFDual) { Util.ConnectDuals(ref primal, ref dual); } //Point3d newCentroid = dual.Centroid; var gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Place the PolyFrame. Hit <Enter> to replace Primal"); gp.SetDefaultPoint(primal.Centroid); gp.AcceptPoint(true); gp.Get(); if (gp.CommandResult() != Result.Success) { return(Result.Failure); } var moveVect = gp.Point() - dual.Centroid; dual.Offset(moveVect); dual.Show(true, true, false); dual.ShowCells(); if (!dual.SaveToDocument(container)) { dual.Hide(); return(Result.Cancel); } dual.Hide(); // also need to update the primal to have a connection to the dual if (!gp.GotDefault()) { var dualJsonString = dual.SerializeJson(); var primalJsonString = primal.SerializeJson(); bool updatedPrimal = false; foreach (var docGeoObj in guids) { //var geomObj = docGeoObj.Object(); var geomObj = doc.Objects.Find(docGeoObj);// docGeoObj.Geometry(); // look for the primal but change the dual. if (geomObj.Geometry.UserDictionary.TryGetString("Primal", out string dummyVal)) { //var objData = docGeoObj.Object(); geomObj.Geometry.UserDictionary.Set("Primal", primalJsonString); geomObj.Geometry.UserDictionary.Set("Dual", dualJsonString); geomObj.CommitChanges(); updatedPrimal = true; break; } } if (updatedPrimal) { Rhino.RhinoApp.WriteLine("Primal geometry was also updated with Dual data."); } else { Rhino.RhinoApp.WriteLine("Failed to update Primal geometry with Dual data."); } } else { doc.Objects.Delete(guids, true); doc.Views.Redraw(); Rhino.RhinoApp.WriteLine("Primal deleted. You can restore it using PFDual command on the result."); } Rhino.RhinoApp.WriteLine($"Constructed a PolyFrame object (dual) with {dual.Cells.Count} cells, {dual.Faces.Count} half-faces, {dual.Edges.Count} half-edges and {dual.Vertices.Count} vertices."); } catch (PolyFrameworkException pfE) { RhinoApp.WriteLine(pfE.Message + " Press <Esc> to continue."); primal.Hide(); dual.Hide(); return(Result.Failure); } return(Result.Success); // TODO: complete command. }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //Pick curve for chain GetObject getCurve = new GetObject(); getCurve.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; getCurve.SetCommandPrompt("Select curve for chain"); var res = getCurve.Get(); Rhino.DocObjects.ObjRef objref = getCurve.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } curve = objref.Curve(); if (curve == null) { return(Result.Failure); } obj.Select(false); //Pick object for chain (instance) //pick objekt to orient GetObject go = new GetObject(); go.SetCommandPrompt("Select chain element."); go.SubObjectSelect = true; go.DeselectAllBeforePostSelect = false; //go.GroupSelect = true; //go.GetMultiple(1, -1); go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } Rhino.DocObjects.ObjRef objref1 = go.Object(0); Rhino.DocObjects.RhinoObject obj1 = objref1.Object(); GeometryBase obj1Base = obj1.Geometry; int obCount = go.ObjectCount; string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); //create block instance and plane for instance Rhino.Input.Custom.GetPoint gp1 = new Rhino.Input.Custom.GetPoint(); gp1.SetCommandPrompt("Center point to orient from"); gp1.Get(); if (gp1.CommandResult() != Rhino.Commands.Result.Success) { return(gp1.CommandResult()); } Point3d pt1 = gp1.Point(); Rhino.Input.Custom.GetPoint gp2 = new Rhino.Input.Custom.GetPoint(); gp2.SetCommandPrompt("Point for orientation"); gp2.DrawLineFromPoint(pt1, false); gp2.Get(); if (gp2.CommandResult() != Rhino.Commands.Result.Success) { return(gp2.CommandResult()); } Point3d pt2 = gp2.Point(); Vector3d vt1 = pt2 - pt1; sourcePlane = new Plane(pt1, vt1); Plane originPlane = new Plane(Point3d.Origin, vt1); Transform bform = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane); obj1Base.Transform(bform); GeometryBase[] obj1List = new GeometryBase[1] { obj1Base }; var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List); //orient instances along curve List <Guid> chainBlocks = new List <Guid>(); Guid chainBlock; while (true) { foreach (var block in chainBlocks) { doc.Objects.Delete(block, false); } chainBlocks = new List <Guid>(); double curveLength = curve.GetLength(); double curveDivide = curveLength / chainDis; int curveDivideInt = Convert.ToInt32(curveDivide); for (int ic = 0; ic < curveDivideInt; ic++) { Point3d insertPoint = curve.PointAtLength(chainDis * ic); Vector3d insertVec = curve.PointAtLength(chainDis * ic + 1) - curve.PointAtLength(chainDis * ic - 1); Plane targetPlane = new Plane(insertPoint, insertVec); var xvec = targetPlane.XAxis; if (xvec.Z != 0) { targetPlane.Rotate(Math.PI / 2, insertVec); } var yvec = targetPlane.YAxis; if (yvec.Z < 0) { targetPlane.Rotate(Math.PI, insertVec); } if (ic % 2 == 0) { targetPlane.Rotate(Math.PI / 2, insertVec); } targetPlane.Rotate(axisOffsetRadiant, insertVec); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, targetPlane); chainBlock = doc.Objects.AddInstanceObject(orientBlock, xform); chainBlocks.Add(chainBlock); } doc.Views.Redraw(); GetOption gd = new GetOption(); gd.SetCommandPrompt("Set distance between element centers in mm and rotation offset in degree. Press enter to accept."); var dis = new Rhino.Input.Custom.OptionDouble(chainDis); var axisOffset = new Rhino.Input.Custom.OptionInteger(chainAxisOffset); gd.AddOptionDouble("distance", ref dis); gd.AddOptionInteger("rotation", ref axisOffset); gd.AcceptNothing(true); var resdis = gd.Get(); if (resdis == GetResult.Nothing) { break; } chainDis = dis.CurrentValue; chainAxisOffset = axisOffset.CurrentValue; axisOffsetRadiant = chainAxisOffset * (Math.PI / 180); } int index = doc.Groups.Add(chainBlocks); return(Result.Success); }
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(); }
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 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; }
public static Result ConduitArrowHeads(RhinoDoc doc) { if (m_draw_conduit != null) { RhinoApp.WriteLine("Turn off existing arrowhead conduit"); m_draw_conduit.Enabled = false; m_draw_conduit = null; } else { // get arrow head size var go = new GetOption(); go.SetCommandPrompt("ArrowHead length in screen size (pixels) or world size (percentage of arrow length)?"); go.AddOption("screen"); go.AddOption("world"); go.Get(); if (go.CommandResult() != Result.Success) return go.CommandResult(); int screen_size = 0; double world_size = 0.0; if (go.Option().EnglishName == "screen") { var gi = new GetInteger(); gi.SetLowerLimit(0, true); gi.SetCommandPrompt("Length of arrow head in pixels"); gi.Get(); if (gi.CommandResult() != Result.Success) return gi.CommandResult(); screen_size = gi.Number(); } else { var gi = new GetInteger(); gi.SetLowerLimit(0, true); gi.SetUpperLimit(100, false); gi.SetCommandPrompt("Length of arrow head in percentage of total arrow length"); gi.Get(); if (gi.CommandResult() != Result.Success) return gi.CommandResult(); world_size = gi.Number() / 100.0; } // get arrow start and end points var gp = new GetPoint(); gp.SetCommandPrompt("Start of line"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var start_point = gp.Point(); gp.SetCommandPrompt("End of line"); gp.SetBasePoint(start_point, false); gp.DrawLineFromPoint(start_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var end_point = gp.Point(); var v = end_point - start_point; if (v.IsTiny(Rhino.RhinoMath.ZeroTolerance)) return Result.Nothing; var line = new Line(start_point, end_point); m_draw_conduit = new DrawArrowHeadsConduit(line, screen_size, world_size); // toggle conduit on/off m_draw_conduit.Enabled = true; RhinoApp.WriteLine("Draw arrowheads conduit enabled."); } doc.Views.Redraw(); return Result.Success; }