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; }
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; }
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; }
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) { 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 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) { 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; }
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; }
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) { //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); }