protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects"); go.EnablePreSelect(true, true); go.EnablePostSelect(true); go.GetMultiple(0, 0); if (go.CommandResult() != Result.Success) return go.CommandResult(); var selected_objects = go.Objects().ToList(); if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); go.DeselectAllBeforePostSelect = false; go.EnableUnselectObjectsOnExit(false); go.GetMultiple(0, 0); if (go.CommandResult() == Result.Success) { foreach (var obj in go.Objects()) { selected_objects.Add(obj); // The normal behavior of commands is that when they finish, // objects that were pre-selected remain selected and objects // that were post-selected will not be selected. Because we // potentially could have both, we'll try to do something // consistent and make sure post-selected objects also stay selected obj.Object().Select(true); } } } return selected_objects.Count > 0 ? Result.Success : Result.Nothing; }
public static Rhino.Commands.Result CircleCenter(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve; go.GetMultiple(1, 0); if( go.CommandResult() != Rhino.Commands.Result.Success ) return go.CommandResult(); Rhino.DocObjects.ObjRef[] objrefs = go.Objects(); if( objrefs==null ) return Rhino.Commands.Result.Nothing; double tolerance = doc.ModelAbsoluteTolerance; for( int i=0; i<objrefs.Length; i++ ) { // get the curve geometry Rhino.Geometry.Curve curve = objrefs[i].Curve(); if( curve==null ) continue; Rhino.Geometry.Circle circle; if( curve.TryGetCircle(out circle, tolerance) ) { Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i+1, circle.Center); } } return Rhino.Commands.Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to copy in place"); go.GroupSelect = true; go.SubObjectSelect = false; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) return go.CommandResult(); var xform = Transform.Identity; var group_map = new Dictionary<int, int>(); foreach (var obj_ref in go.Objects()) { if (obj_ref != null) { var obj = obj_ref.Object(); var duplicate = doc.Objects.Transform(obj_ref.ObjectId, xform, false); RhinoUpdateObjectGroups(ref obj, ref group_map); } } doc.Views.Redraw(); return Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select block to explode"); go.GeometryFilter = ObjectType.InstanceReference; go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var iref = go.Object(0).Object() as Rhino.DocObjects.InstanceObject; if (null == iref) { return(Result.Failure); } var xform = Transform.Identity; bool rc = ExplodeBlockHelper(doc, iref, xform); if (rc) { doc.Objects.Delete(go.Object(0), false); doc.Views.Redraw(); } return(Result.Success); }
public static Result CopyGroups(RhinoDoc doc) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to copy in place"); go.GroupSelect = true; go.SubObjectSelect = false; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var xform = Transform.Identity; var group_map = new Dictionary <int, int>(); foreach (var obj_ref in go.Objects()) { if (obj_ref != null) { var obj = obj_ref.Object(); var duplicate = doc.Objects.Transform(obj_ref.ObjectId, xform, false); RhinoUpdateObjectGroups(ref obj, ref group_map); } } doc.Views.Redraw(); return(Result.Success); }
public static Rhino.Commands.Result AddObjectsToGroup(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to group"); go.GroupSelect = true; go.GetMultiple(1, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } List <Guid> ids = new List <Guid>(); for (int i = 0; i < go.ObjectCount; i++) { ids.Add(go.Object(i).ObjectId); } int index = doc.Groups.Add(ids); doc.Views.Redraw(); if (index >= 0) { return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
public static Rhino.Commands.Result TweenCurve(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select two curves"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GetMultiple(2, 2); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.Geometry.Curve curve0 = go.Object(0).Curve(); Rhino.Geometry.Curve curve1 = go.Object(1).Curve(); if (null != curve0 && null != curve1) { Rhino.Geometry.Curve[] curves = Rhino.Geometry.Curve.CreateTweenCurves(curve0, curve1, 1); if (null != curves) { for (int i = 0; i < curves.Length; i++) { doc.Objects.AddCurve(curves[i]); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } } return(Rhino.Commands.Result.Failure); }
public static Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc) { Rhino.DocObjects.ObjRef rail_ref; var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref); if (rc != Rhino.Commands.Result.Success) { return(rc); } var rail_crv = rail_ref.Curve(); if (rail_crv == null) { return(Rhino.Commands.Result.Failure); } var gx = new Rhino.Input.Custom.GetObject(); gx.SetCommandPrompt("Select cross section curves"); gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gx.EnablePreSelect(false, true); gx.GetMultiple(1, 0); if (gx.CommandResult() != Rhino.Commands.Result.Success) { return(gx.CommandResult()); } var cross_sections = new List <Rhino.Geometry.Curve>(); for (int i = 0; i < gx.ObjectCount; i++) { var crv = gx.Object(i).Curve(); if (crv != null) { cross_sections.Add(crv); } } if (cross_sections.Count < 1) { return(Rhino.Commands.Result.Failure); } var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians; sweep.ClosedSweep = false; sweep.SweepTolerance = doc.ModelAbsoluteTolerance; sweep.SetToRoadlikeTop(); var breps = sweep.PerformSweep(rail_crv, cross_sections); for (int i = 0; i < breps.Length; i++) { doc.Objects.AddBrep(breps[i]); } doc.Views.Redraw(); 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 objects to define block Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select surface or polysurface to box morph"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep; go.SubObjectSelect = false; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.Geometry.Brep brep = go.Object(0).Brep(); if (null == brep) { return(Result.Failure); } Rhino.Geometry.BoundingBox bbox = brep.GetBoundingBox(true); // The original box points Rhino.Geometry.Point3d[] box = new Rhino.Geometry.Point3d[8]; box[0] = bbox.Corner(true, true, true); box[1] = bbox.Corner(false, true, true); box[2] = bbox.Corner(false, false, true); box[3] = bbox.Corner(true, false, true); box[4] = bbox.Corner(true, true, false); box[5] = bbox.Corner(false, true, false); box[6] = bbox.Corner(false, false, false); box[7] = bbox.Corner(true, false, false); // The modified box points Rhino.Geometry.Point3d[] corners = new Rhino.Geometry.Point3d[8]; corners[0] = box[0]; corners[1] = box[1]; corners[2] = box[2]; corners[3] = box[3]; corners[4] = box[4]; corners[5] = box[5]; corners[6] = box[6] * 2; // some goofy point corners[7] = box[7]; BoxMorph box_morph = new BoxMorph(box, corners); if (box_morph.IsValid() && !box_morph.IsIdentity()) { if (box_morph.Morph(brep)) { doc.Objects.Add(brep); doc.Views.Redraw(); } } return(Result.Success); }
public static Rhino.Commands.Result HatchCurve(Rhino.RhinoDoc doc) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select closed planar curve"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve; go.SubObjectSelect = false; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } var curve = go.Object(0).Curve(); if (curve == null || !curve.IsClosed || !curve.IsPlanar()) { return(Rhino.Commands.Result.Failure); } string hatch_name = doc.HatchPatterns[doc.HatchPatterns.CurrentHatchPatternIndex].Name; var rc = Rhino.Input.RhinoGet.GetString("Hatch pattern", true, ref hatch_name); if (rc != Rhino.Commands.Result.Success) { return(rc); } hatch_name = hatch_name.Trim(); if (string.IsNullOrWhiteSpace(hatch_name)) { return(Rhino.Commands.Result.Nothing); } int index = doc.HatchPatterns.Find(hatch_name, true); if (index < 0) { Rhino.RhinoApp.WriteLine("Hatch pattern does not exist."); return(Rhino.Commands.Result.Nothing); } var hatches = Rhino.Geometry.Hatch.Create(curve, index, 0, 1); for (int i = 0; i < hatches.Length; i++) { doc.Objects.AddHatch(hatches[i]); } if (hatches.Length > 0) { doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result IntersectLines(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select lines"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GetMultiple(2, 2); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } if (go.ObjectCount != 2) { return(Rhino.Commands.Result.Failure); } LineCurve crv0 = go.Object(0).Geometry() as LineCurve; LineCurve crv1 = go.Object(1).Geometry() as LineCurve; if (crv0 == null || crv1 == null) { return(Rhino.Commands.Result.Failure); } Line line0 = crv0.Line; Line line1 = crv1.Line; Vector3d v0 = line0.Direction; v0.Unitize(); Vector3d v1 = line1.Direction; v1.Unitize(); if (v0.IsParallelTo(v1) != 0) { Rhino.RhinoApp.WriteLine("Selected lines are parallel."); return(Rhino.Commands.Result.Nothing); } double a, b; if (!Rhino.Geometry.Intersect.Intersection.LineLine(line0, line1, out a, out b)) { Rhino.RhinoApp.WriteLine("No intersection found."); return(Rhino.Commands.Result.Nothing); } Point3d pt0 = line0.PointAt(a); doc.Objects.AddPoint(pt0); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. RhinoApp.WriteLine("The {0} command is under construction.", EnglishName); Rhino.Input.Custom.GetObject gmesh = new Rhino.Input.Custom.GetObject(); gmesh.SetCommandPrompt("Get the Mesh"); gmesh.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh; gmesh.SubObjectSelect = true; gmesh.Get(); if (gmesh.CommandResult() != Rhino.Commands.Result.Success) { return(gmesh.CommandResult()); } Rhino.DocObjects.ObjRef objref = gmesh.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Mesh mesh = objref.Mesh(); if (mesh == null) { return(Rhino.Commands.Result.Failure); } obj.Select(false); MeshTextureCoordinateList texture_list = mesh.TextureCoordinates; for (int i = 0; i < texture_list.Count - 1; i++) { Point2f f1 = texture_list[i]; Point2f f2 = texture_list[i + 1]; Point3d t1 = new Point3d(f1.X, f1.Y, 0); Point3d t2 = new Point3d(f2.X, f2.Y, 0); Line l = new Line(t1, t2); doc.Objects.AddLine(l); RhinoApp.WriteLine("Line added"); } doc.Views.Redraw(); MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; p.painted_object_ = mesh; p.if_painted_object_set_ = true; mesh.UserDictionary.Set("name", "myMesh"); mesh.UserDictionary.Set("isMovable", false); p.graph = new DijkstraGraph(10); RhinoApp.WriteLine("Mesh Got"); return(Result.Success); }
public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to flow", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject(); go0.SetCommandPrompt("Source curve"); go0.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go0.SubObjectSelect = false; go0.EnablePreSelect(false, true); go0.DeselectAllBeforePostSelect = false; go0.Get(); if (go0.CommandResult() != Rhino.Commands.Result.Success) { return(go0.CommandResult()); } Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0); Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject(); go1.SetCommandPrompt("Source curve"); go1.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go1.SubObjectSelect = false; go1.EnablePreSelect(false, true); go1.DeselectAllBeforePostSelect = false; go1.Get(); if (go1.CommandResult() != Rhino.Commands.Result.Success) { return(go1.CommandResult()); } Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0); Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result ExtrudeBrepFace(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject(); go0.SetCommandPrompt("Select surface to extrude"); go0.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go0.SubObjectSelect = true; go0.Get(); if (go0.CommandResult() != Rhino.Commands.Result.Success) { return(go0.CommandResult()); } Rhino.Geometry.BrepFace face = go0.Object(0).Face(); if (null == face) { return(Rhino.Commands.Result.Failure); } Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject(); go1.SetCommandPrompt("Select path curve"); go1.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go1.SubObjectSelect = true; go1.DeselectAllBeforePostSelect = false; go1.Get(); if (go1.CommandResult() != Rhino.Commands.Result.Success) { return(go1.CommandResult()); } Rhino.Geometry.Curve curve = go1.Object(0).Curve(); if (null == curve) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Brep brep = face.CreateExtrusion(curve, true); if (null != brep) { doc.Objects.Add(brep); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result IntersectCurves(Rhino.RhinoDoc doc) { // Select two curves to intersect var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select two curves"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GetMultiple(2, 2); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } // Validate input var curveA = go.Object(0).Curve(); var curveB = go.Object(1).Curve(); if (curveA == null || curveB == null) { return(Rhino.Commands.Result.Failure); } // Calculate the intersection const double intersection_tolerance = 0.001; const double overlap_tolerance = 0.0; var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curveA, curveB, intersection_tolerance, overlap_tolerance); // Process the results if (events != null) { for (int i = 0; i < events.Count; i++) { var ccx_event = events[i]; doc.Objects.AddPoint(ccx_event.PointA); if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon) { doc.Objects.AddPoint(ccx_event.PointB); doc.Objects.AddLine(ccx_event.PointA, ccx_event.PointB); } } doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to splop", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Surface to splop on"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go.SubObjectSelect = false; go.EnablePreSelect(false, true); go.DeselectAllBeforePostSelect = false; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.DocObjects.ObjRef srfref = go.Object(0); double u, v; srfref.SurfaceParameter(out u, out v); Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u, v); Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select surface or polysurface to smash"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.Geometry.Brep brep = go.Object(0).Brep(); if (null == brep) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Unroller unroller = new Rhino.Geometry.Unroller(brep); unroller.AbsoluteTolerance = doc.ModelAbsoluteTolerance; unroller.RelativeTolerance = 1.0; // big relative tolerance for smash unroller.ExplodeSpacing = 2.0; unroller.ExplodeOutput = true; Rhino.Geometry.Curve[] unrolledCurves = null; Rhino.Geometry.Point3d[] unrolledPoints = null; Rhino.Geometry.TextDot[] unrolledDots = null; Rhino.Geometry.Brep[] output = unroller.PerformUnroll(out unrolledCurves, out unrolledPoints, out unrolledDots); if (null != output) { for (int i = 0; i < output.Length; i++) { doc.Objects.Add(output[i]); } } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { Mesh meshObj; Point3d pointObj = new Point3d(0.0,0.0,0.0); RhinoApp.WriteLine("dikka dikka dikka..."); Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Start of ray"); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); pointObj = gp.Point(); doc.Objects.AddPoint(pointObj); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select the mesh to print"); go.Get(); Result rc = go.CommandResult(); if (rc != Rhino.Commands.Result.Success) { RhinoApp.WriteLine("sdfafadsfda"); return rc; } RhinoApp.WriteLine("2 2 dikka dikka dikka..."); meshObj = new Mesh(); if (go.ObjectCount == 1) { ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId); meshObj = tmpRef.Mesh(); if (meshObj == null) { return rc; } } Ray3d rayObj = new Ray3d(pointObj, new Vector3d(1.0, 1.0, 1.0)); doc.Objects.AddPoint(rayObj.PointAt(1.0)); doc.Objects.AddPoint(rayObj.PointAt(2.0)); doc.Objects.AddPoint(rayObj.PointAt(3.0)); double p = Intersection.MeshRay(meshObj, rayObj); string a = string.Format("mesh ray gives {0:0.00}",p); doc.Objects.AddPoint(rayObj.PointAt(p)); RhinoApp.WriteLine(a); return Rhino.Commands.Result.Success; }
public static Rhino.Commands.Result LineBetweenCurves(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select two curves"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GetMultiple(2, 2); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.DocObjects.ObjRef objRef0 = go.Object(0); Rhino.DocObjects.ObjRef objRef1 = go.Object(1); double t0 = Rhino.RhinoMath.UnsetValue; double t1 = Rhino.RhinoMath.UnsetValue; Rhino.Geometry.Curve curve0 = objRef0.CurveParameter(out t0); Rhino.Geometry.Curve curve1 = objRef1.CurveParameter(out t1); if (null == curve0 || !Rhino.RhinoMath.IsValidDouble(t0) || null == curve1 || !Rhino.RhinoMath.IsValidDouble(t1)) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Line line = Rhino.Geometry.Line.Unset; bool rc = Rhino.Geometry.Line.TryCreateBetweenCurves(curve0, curve1, ref t0, ref t1, false, false, out line); if (rc) { if (Guid.Empty != doc.Objects.AddLine(line)) { doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } } return(Rhino.Commands.Result.Failure); }
public static Rhino.Commands.Result IntersectCurves(Rhino.RhinoDoc doc) { // Select two curves to intersect var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select two curves"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GetMultiple(2, 2); if (go.CommandResult() != Rhino.Commands.Result.Success) return go.CommandResult(); // Validate input var curveA = go.Object(0).Curve(); var curveB = go.Object(1).Curve(); if (curveA == null || curveB == null) return Rhino.Commands.Result.Failure; // Calculate the intersection const double intersection_tolerance = 0.001; const double overlap_tolerance = 0.0; var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curveA, curveB, intersection_tolerance, overlap_tolerance); // Process the results if (events != null) { for (int i = 0; i < events.Count; i++) { var ccx_event = events[i]; doc.Objects.AddPoint(ccx_event.PointA); if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon) { doc.Objects.AddPoint(ccx_event.PointB); doc.Objects.AddLine(ccx_event.PointA, ccx_event.PointB); } } doc.Views.Redraw(); } return Rhino.Commands.Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects"); go.EnablePreSelect(true, true); go.EnablePostSelect(true); go.GetMultiple(0, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var selected_objects = go.Objects().ToList(); if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); go.DeselectAllBeforePostSelect = false; go.EnableUnselectObjectsOnExit(false); go.GetMultiple(0, 0); if (go.CommandResult() == Result.Success) { foreach (var obj in go.Objects()) { selected_objects.Add(obj); // The normal behavior of commands is that when they finish, // objects that were pre-selected remain selected and objects // that were post-selected will not be selected. Because we // potentially could have both, we'll try to do something // consistent and make sure post-selected objects also stay selected obj.Object().Select(true); } } } return(selected_objects.Count > 0 ? Result.Success : Result.Nothing); }
public static Rhino.Commands.Result ExtrudeBrepFace(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject(); go0.SetCommandPrompt("Select surface to extrude"); go0.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go0.SubObjectSelect = true; go0.Get(); if (go0.CommandResult() != Rhino.Commands.Result.Success) return go0.CommandResult(); Rhino.Geometry.BrepFace face = go0.Object(0).Face(); if (null == face) return Rhino.Commands.Result.Failure; Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject(); go1.SetCommandPrompt("Select path curve"); go1.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go1.SubObjectSelect = true; go1.DeselectAllBeforePostSelect = false; go1.Get(); if (go1.CommandResult() != Rhino.Commands.Result.Success) return go1.CommandResult(); Rhino.Geometry.Curve curve = go1.Object(0).Curve(); if (null == curve) return Rhino.Commands.Result.Failure; Rhino.Geometry.Brep brep = face.CreateExtrusion(curve, true); if (null != brep) { doc.Objects.Add(brep); doc.Views.Redraw(); } return Rhino.Commands.Result.Success; }
public static Rhino.Commands.Result HatchCurve(Rhino.RhinoDoc doc) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select closed planar curve"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve; go.SubObjectSelect = false; go.Get(); if( go.CommandResult() != Rhino.Commands.Result.Success ) return go.CommandResult(); var curve = go.Object(0).Curve(); if( curve==null || !curve.IsClosed || !curve.IsPlanar() ) return Rhino.Commands.Result.Failure; string hatch_name = doc.HatchPatterns[doc.HatchPatterns.CurrentHatchPatternIndex].Name; var rc = Rhino.Input.RhinoGet.GetString("Hatch pattern", true, ref hatch_name); if( rc!= Rhino.Commands.Result.Success ) return rc; hatch_name = hatch_name.Trim(); if( string.IsNullOrWhiteSpace(hatch_name) ) return Rhino.Commands.Result.Nothing; int index = doc.HatchPatterns.Find(hatch_name, true); if( index < 0 ) { Rhino.RhinoApp.WriteLine("Hatch pattern does not exist."); return Rhino.Commands.Result.Nothing; } var hatches = Rhino.Geometry.Hatch.Create( curve, index, 0, 1); for( int i=0; i<hatches.Length; i++ ) doc.Objects.AddHatch(hatches[i]); if( hatches.Length>0 ) doc.Views.Redraw(); return Rhino.Commands.Result.Success; }
public static Rhino.Commands.Result CircleCenter(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve; go.GetMultiple(1, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.DocObjects.ObjRef[] objrefs = go.Objects(); if (objrefs == null) { return(Rhino.Commands.Result.Nothing); } double tolerance = doc.ModelAbsoluteTolerance; for (int i = 0; i < objrefs.Length; i++) { // get the curve geometry Rhino.Geometry.Curve curve = objrefs[i].Curve(); if (curve == null) { continue; } Rhino.Geometry.Circle circle; if (curve.TryGetCircle(out circle, tolerance)) { Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i + 1, circle.Center); } } return(Rhino.Commands.Result.Success); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { pluginObj = ((nishanchiPlugin)this.PlugIn); RhinoView viewObj = doc.Views.ActiveView; RhinoViewport viewPortObj = viewObj.ActiveViewport; Vector3d originalCameraVector = viewPortObj.CameraDirection; Point3d originalCameraLocation = viewPortObj.CameraLocation; Mesh meshObj; Boolean logging = false; StreamWriter logWriter = null; String reportString; String logString; String printCommandStr; if (((nishanchiPlugin)this.PlugIn).logEnabled()) { logWriter = new StreamWriter(((nishanchiPlugin)this.PlugIn).getNewLogFile()); logWriter.WriteLine("Printing..."); logging = true; } if (!pluginObj.trackerConnected) { RhinoApp.WriteLine("Tracker disconnected"); return Rhino.Commands.Result.Failure; } connectKbEvt(); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select the mesh to print"); go.Get(); Result rc = go.CommandResult(); if (rc != Rhino.Commands.Result.Success) { disconnectKbEvt(); return rc; } meshObj = new Mesh(); if (go.ObjectCount == 1){ ObjRef tmpRef = new ObjRef(go.Object(0).ObjectId); meshObj = tmpRef.Mesh(); if (meshObj == null){ disconnectKbEvt(); return rc; } } createNozzles(doc); cameraPoint = new tPoint(Nozzle.XOffset + 100.0, Nozzle.YOffset, Nozzle.ZOffset + (Nozzle.ZMultiplier * ((numNozzles-1)/2))); fastrak trackerObj = pluginObj.trackerObj; int numPoints = 0; Boolean retval; RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker.")); pluginObj.trackerObj.setContinuous(); RhinoApp.WriteLine(string.Format("Printing mode enabled now.")); running = true; while (running) { retval = trackerObj.readFrame(); if (retval) { //q0,q1,q2,q3 Quaternion begin //Compute the rotation matrix reportString = String.Format("{0},{1},{2}", trackerObj.x, trackerObj.y, trackerObj.z); logString = String.Format("p,{0},{1},{2},{3},{4},{5},{6},{7}", numPoints, trackerObj.x, trackerObj.y, trackerObj.z, trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3); RhinoApp.WriteLine(reportString); if (logging) { logWriter.WriteLine(logString); } rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z); orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3); orientationQuat.GetRotation(out angle, out axis); rotMat = Transform.Rotation(angle, axis, origin); // Compute the new positions for the nozzlePoints and also compute the new lines for (int i = 0; i < numNozzles; i++) { nozzles[i].computeTxTx(rotMat, rxTxTx); } //And, I move the view around if ((numPoints % 100) == 0) { cameraPoint.computeTxTx(rotMat, rxTxTx); viewPortObj.SetCameraLocation(cameraPoint.txTx(), true); viewPortObj.SetCameraDirection(nozzles[4].vector(), true); viewPortObj.Rotate(Math.PI / 2, nozzles[4].vector(), cameraPoint.txTx()); cameraUpTx = rotMat * cameraUpRx; viewPortObj.CameraUp = cameraUpTx; removeNozzleLinesFromDocument(doc); addNozzleLinesToDocument(doc); doc.Views.ActiveView.Redraw(); RhinoApp.Wait(); } //Compute ray intersections if ((numPoints % 4) == 0) { //RhinoApp.WriteLine("Calculating intersections.."); for (int i = 0; i < numNozzles; i++) { nozzles[i].rayIntersectionDistance = Intersection.MeshRay(meshObj,nozzles[i].ray()); } printCommandStr = printCommand(); //RhinoApp.WriteLine(printCommandStr); if (logging) { logString = String.Format("c,{0},{1}", numPoints, printCommandStr); logWriter.WriteLine(logString); } } numPoints++; } } running = false; //clean up removeNozzleLinesFromDocument(doc); doc.Views.ActiveView.Redraw(); RhinoApp.WriteLine("Removing printHead objects!!"); if (logging) { logWriter.Close(); ((nishanchiPlugin)this.PlugIn).closeLogFile(); } //stop the tracker RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker.")); pluginObj.trackerObj.stopContinuous(); disconnectKbEvt(); RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!")); //setup the viewport as it was viewPortObj.SetCameraLocation(originalCameraLocation, true); viewPortObj.SetCameraDirection(originalCameraVector, true); 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 Result RunCommand(RhinoDoc doc, RunMode mode) { // Pick some objects to smooth Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to smooth"); go.SubObjectSelect = false; go.ReferenceObjectSelect = false; go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Mesh; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } // Prompt for some command line options. In this case, // we will clone the -Smooth command. Rhino.Input.Custom.GetOption gs = new Rhino.Input.Custom.GetOption(); gs.SetCommandPrompt("Choose smooth option"); gs.AcceptNothing(true); for (; ;) { gs.ClearCommandOptions(); Rhino.Input.Custom.OptionDouble smooth_factor_option = new Rhino.Input.Custom.OptionDouble(m_smooth_factor); Rhino.Input.Custom.OptionToggle use_cplane_option = new Rhino.Input.Custom.OptionToggle(m_use_cplane, "World", "CPlane"); Rhino.Input.Custom.OptionToggle smooth_x_option = new Rhino.Input.Custom.OptionToggle(m_smooth_x, "No", "Yes"); Rhino.Input.Custom.OptionToggle smooth_y_option = new Rhino.Input.Custom.OptionToggle(m_smooth_y, "No", "Yes"); Rhino.Input.Custom.OptionToggle smooth_z_option = new Rhino.Input.Custom.OptionToggle(m_smooth_z, "No", "Yes"); Rhino.Input.Custom.OptionToggle fix_boundaries_option = new Rhino.Input.Custom.OptionToggle(m_fix_boundaries, "No", "Yes"); int smooth_factor_index = gs.AddOptionDouble("SmoothFactor", ref smooth_factor_option); int use_cplane_index = gs.AddOptionToggle("CoordinateSystem", ref use_cplane_option); int smooth_x_index = gs.AddOptionToggle("X", ref smooth_x_option); int smooth_y_index = gs.AddOptionToggle("Y", ref smooth_y_option); int smooth_z_index = gs.AddOptionToggle("Z", ref smooth_z_option); int fix_boundaries_index = gs.AddOptionToggle("FixBoundaries", ref fix_boundaries_option); Rhino.Input.GetResult getrc = gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } if (getrc == Rhino.Input.GetResult.Option) { int index = gs.OptionIndex(); if (index == smooth_factor_index) { m_smooth_factor = smooth_factor_option.CurrentValue; } else if (index == use_cplane_index) { m_use_cplane = use_cplane_option.CurrentValue; } else if (index == smooth_x_index) { m_smooth_x = smooth_x_option.CurrentValue; } else if (index == smooth_y_index) { m_smooth_y = smooth_y_option.CurrentValue; } else if (index == smooth_z_index) { m_smooth_z = smooth_z_option.CurrentValue; } else if (index == fix_boundaries_index) { m_fix_boundaries = fix_boundaries_option.CurrentValue; } continue; } break; } // Build a command line macro that we can script StringBuilder sb = new StringBuilder(); sb.Append("_-Smooth "); sb.Append(string.Format("_SmoothFactor={0} ", m_smooth_factor)); sb.Append(string.Format("_CoordinateSystem={0} ", m_use_cplane ? "_CPlane" : "_World")); sb.Append(string.Format("_X={0} ", m_smooth_x ? "_Yes" : "_No")); sb.Append(string.Format("_Y={0} ", m_smooth_y ? "_Yes" : "_No")); sb.Append(string.Format("_Z={0} ", m_smooth_z ? "_Yes" : "_No")); sb.Append(string.Format("_FixBoundaries={0} ", m_fix_boundaries ? "_Yes" : "_No")); sb.Append("_Enter"); string script = sb.ToString(); #if (!RELEASE) Rhino.RhinoApp.WriteLine(script); #endif // Script the smooth command Rhino.RhinoApp.RunScript(script, false); return(Result.Success); }
/// <summary> /// Select an object which will be used for the user text list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GetObjectForUserText(object sender, EventArgs e) { using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()) { go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select object", 361)); go.AcceptNothing(true); go.DisablePreSelect(); go.Get(); if (go.CommandResult() == Rhino.Commands.Result.Success) { Rhino.DocObjects.ObjRef objref = go.Object(0); if (objref != null) { SelectedObjectId = objref.ObjectId; SetupSelectObjectPanelHelper(TextFieldType.usertext, false); objref.Dispose(); } } } }
public static Commands.Result GetMultipleObjects(string prompt, bool acceptNothing, Rhino.DocObjects.ObjectType filter, out Rhino.DocObjects.ObjRef[] rhObjects) { rhObjects = null; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt(prompt); go.AcceptNothing(acceptNothing); go.GeometryFilter = filter; go.GetMultiple(1, 0); //David: changed this from GetMultiple(1, -1), which is a much rarer case (imo). Commands.Result rc = go.CommandResult(); if (rc == Rhino.Commands.Result.Success && go.ObjectCount > 0) { rhObjects = go.Objects(); } go.Dispose(); return rc; }
public static Commands.Result GetOneObject(string prompt, bool acceptNothing, Rhino.DocObjects.ObjectType filter, out Rhino.DocObjects.ObjRef rhObject) { rhObject = null; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt(prompt); go.AcceptNothing(acceptNothing); go.GeometryFilter = filter; go.Get(); Commands.Result rc = go.CommandResult(); if (rc == Rhino.Commands.Result.Success && go.ObjectCount > 0) { rhObject = go.Object(0); } go.Dispose(); return rc; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select sphere"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedSurface; go.SubObjectSelect = false; go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } Rhino.Geometry.Brep brep = go.Object(0).Brep(); if (null == brep || 1 != brep.Faces.Count) { return(Result.Failure); } Rhino.Geometry.Surface srf = brep.Faces[0].UnderlyingSurface(); if (null == srf) { return(Result.Failure); } Rhino.Geometry.Sphere sphere; if (!srf.TryGetSphere(out sphere)) { RhinoApp.WriteLine("Surface is not a sphere"); return(Result.Nothing); } Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber(); gn.SetCommandPrompt("New radius"); gn.SetDefaultNumber(sphere.Radius); gn.SetLowerLimit(1.0, false); // or whatever you deem appripriate... gn.Get(); if (gn.CommandResult() != Result.Success) { return(gn.CommandResult()); } sphere.Radius = gn.Number(); // Sometimes, Surface.TryGetSphere() will return a sphere with a left-handed // plane. So, ensure the plane is right-handed. Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane( sphere.EquitorialPlane.Origin, sphere.EquitorialPlane.XAxis, sphere.EquitorialPlane.YAxis ); sphere.EquitorialPlane = plane; Rhino.Geometry.RevSurface rev_srf = sphere.ToRevSurface(); if (null != rev_srf) { doc.Objects.Replace(go.Object(0).ObjectId, rev_srf); doc.Views.Redraw(); } return(Result.Success); }
static Commands.Result GetGripsHelper(out Rhino.DocObjects.GripObject[] grips, string prompt, bool singleGrip) { grips = null; using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()) { if (!string.IsNullOrEmpty(prompt)) go.SetCommandPrompt(prompt); go.SubObjectSelect = false; go.GeometryFilter = Rhino.DocObjects.ObjectType.Grip; go.GroupSelect = false; go.AcceptNothing(true); if (singleGrip) go.Get(); else go.GetMultiple(1, 0); Commands.Result rc = go.CommandResult(); if (Rhino.Commands.Result.Success == rc) { Rhino.DocObjects.ObjRef[] objrefs = go.Objects(); if (null != objrefs && objrefs.Length > 0) { System.Collections.Generic.List<Rhino.DocObjects.GripObject> griplist = new System.Collections.Generic.List<Rhino.DocObjects.GripObject>(); for (int i = 0; i < objrefs.Length; i++) { Rhino.DocObjects.ObjRef ob = objrefs[i]; if (null == ob) continue; Rhino.DocObjects.GripObject grip = ob.Object() as Rhino.DocObjects.GripObject; if (grip != null) griplist.Add(grip); ob.Dispose(); } if (griplist.Count > 0) grips = griplist.ToArray(); } } return rc; } }
public static Result ExtendSurface(RhinoDoc doc) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select edge of surface to extend"); go.GeometryFilter = ObjectType.EdgeFilter; go.GeometryAttributeFilter = GeometryAttributeFilter.EdgeCurve; go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var obj_ref = go.Object(0); var surface = obj_ref.Surface(); if (surface == null) { RhinoApp.WriteLine("Unable to extend polysurfaces."); return(Result.Failure); } var brep = obj_ref.Brep(); var face = obj_ref.Face(); if (brep == null || face == null) { return(Result.Failure); } if (face.FaceIndex < 0) { return(Result.Failure); } if (!brep.IsSurface) { RhinoApp.WriteLine("Unable to extend trimmed surfaces."); return(Result.Nothing); } var curve = obj_ref.Curve(); var trim = obj_ref.Trim(); if (trim == null) { return(Result.Failure); } if (trim.TrimType == BrepTrimType.Seam) { RhinoApp.WriteLine("Unable to extend surface at seam."); return(Result.Nothing); } var extended_surface = surface.Extend(trim.IsoStatus, 5.0, true); if (extended_surface != null) { var mybrep = Brep.CreateFromSurface(extended_surface); doc.Objects.Replace(obj_ref.ObjectId, mybrep); doc.Views.Redraw(); } return(Result.Success); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { nishanchiPlugin pluginObj = ((nishanchiPlugin)this.PlugIn); Boolean selectedObjectIsBrep = false; Boolean selectedObjectIsCurve = false; if (!pluginObj.trackerConnected) { RhinoApp.WriteLine("Tracker disconnected"); return Rhino.Commands.Result.Failure; } connectKbEvt(); //Ask the user to select Breps to print. //Result rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select the surfaces to print", //false, Rhino.DocObjects.ObjectType.Surface, out objrefs); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select the entity to print"); go.GroupSelect = true; //Set this to go.GetMultiple(0,0) if you want to allow multiple entities to be selected go.GetMultiple(0, 1); Result rc = go.CommandResult(); if (rc != Rhino.Commands.Result.Success) { disconnectKbEvt(); return rc; } List<Rhino.Geometry.Brep> breps = new List<Rhino.Geometry.Brep>(); List<Rhino.Geometry.Curve> curves = new List<Rhino.Geometry.Curve>(); for (int i = 0; i < go.ObjectCount; i++) { ObjRef tmpRef = new ObjRef(go.Object(i).ObjectId); Rhino.Geometry.Brep brep = tmpRef.Brep(); if (brep != null) { breps.Add(brep); selectedObjectIsBrep = true; } Rhino.Geometry.Curve curve = tmpRef.Curve(); if (curve != null) { curves.Add(curve); selectedObjectIsCurve = true; } } if (selectedObjectIsBrep) RhinoApp.WriteLine("Selected " + breps.Count + " surfaces! Good! No, not, really, I'm just a program, I couldn't care less."); if (selectedObjectIsCurve) RhinoApp.WriteLine("Selected " + curves.Count + " curves! Good! No, not, really, I'm just a program, I couldn't care less."); createEntities(doc); fastrak trackerObj = pluginObj.trackerObj; int numPoints = 0; int numIntersections = 0; Boolean retval; RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker.")); pluginObj.trackerObj.setContinuous(); RhinoApp.WriteLine(string.Format("Printing mode enabled now.")); Curve[] intersectionCurves; Point3d[] intersectionPoints; running = true; while (running) { retval = trackerObj.readFrame(); if (retval) { //q0,q1,q2,q3 Quaternion begin //Compute the rotation matrix rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z); orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3); orientationQuat.GetRotation(out angle, out axis); rotMat = Transform.Rotation(angle, axis, origin); // Compute the new positions for the nozzlePoints and also compute the new lines for (int i = 0; i < numNozzles; i++) { nozzleStartPointRxTx[i] = rotMat * nozzleStartPointRxRx[i]; nozzleStartPointTxTx[i] = nozzleStartPointRxTx[i] + rxTxTx; nozzleEndPointRxTx[i] = rotMat * nozzleEndPointRxRx[i]; nozzleEndPointTxTx[i] = nozzleEndPointRxTx[i] + rxTxTx; nozzleLinesTx[i] = new Line(nozzleStartPointTxTx[i], nozzleEndPointTxTx[i]); nozzleCurves[i] = new LineCurve(nozzleLinesTx[i]); } numIntersections = 0; if (selectedObjectIsBrep) { for (int i = 0; i < numNozzles; i++) { foreach (Brep b in breps) { try { Intersection.CurveBrep(nozzleCurves[i], b, nozzleTolerance, out intersectionCurves, out intersectionPoints); if (intersectionPoints.Length > 0) { intersectionsBits[i] = 1; numIntersections++; } else { intersectionsBits[i] = 0; } } catch (Exception e) { RhinoApp.WriteLine(e.Message); } } } } if (selectedObjectIsCurve) { for (int i = 0; i < numNozzles; i++) { foreach (Curve c in curves) { try { var events = Intersection.CurveCurve(nozzleCurves[i], c, nozzleTolerance, nozzleTolerance); if (events != null) { if (events.Count >= 1) { intersectionsBits[i] = 1; numIntersections++; } else { intersectionsBits[i] = 0; } } } catch (Exception e) { RhinoApp.WriteLine(e.Message); } } } } if (pluginObj.printHeadConnected) { // I print if (((numPoints % 5) == 0)&&(numIntersections > 0)) { string p = printCommand(); //RhinoApp.WriteLine(p); pluginObj.printHeadObj.printFrame(p); //pluginObj.printHeadObj.printFullLine(); } } numPoints++; } //And, I move the printer like thing on the screen if ((numPoints % 10) == 0) { for (int i = 0; i < numNozzles; i++) { doc.Objects.Delete(lineGuids[i],false); lineGuids[i] = doc.Objects.AddLine(nozzleLinesTx[i]); } doc.Objects.Delete(ballGuid, false); ball = new Sphere(rxTxTx, ballRadius); ballGuid = doc.Objects.AddSphere(ball); doc.Views.ActiveView.Redraw(); RhinoApp.Wait(); } } running = false; removeEntities(doc); RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker.")); pluginObj.trackerObj.stopContinuous(); disconnectKbEvt(); RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!")); return Rhino.Commands.Result.Success; }
/// <summary> /// Select an object for object name display /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GetObjectForName(object sender, EventArgs e) { using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()) { go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select object", 384)); go.AcceptNothing(true); go.SubObjectSelect = false; go.DisablePreSelect(); go.Get(); if (go.CommandResult() == Rhino.Commands.Result.Success) { Rhino.DocObjects.ObjRef objref = go.Object(0); if (objref != null) { SelectedObjectId = objref.ObjectId; objref.Dispose(); } } } }
public static Rhino.Commands.Result UnrollSurface(Rhino.RhinoDoc doc) { const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface; Rhino.DocObjects.ObjRef objref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Geometry.Unroller unroll = null; Rhino.Geometry.Brep brep = objref.Brep(); if (brep != null) { unroll = new Rhino.Geometry.Unroller(brep); } else { Rhino.Geometry.Surface srf = objref.Surface(); if (srf != null) { unroll = new Rhino.Geometry.Unroller(srf); } } if (unroll == null) { return(Rhino.Commands.Result.Cancel); } unroll.AbsoluteTolerance = 0.01; unroll.RelativeTolerance = 0.01; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select points, curves, and dots to unroll with surface"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.TextDot; go.AcceptNothing(true); go.GetMultiple(0, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } for (int i = 0; i < go.ObjectCount; i++) { objref = go.Object(i); Rhino.Geometry.GeometryBase g = objref.Geometry(); Rhino.Geometry.Point pt = g as Rhino.Geometry.Point; Rhino.Geometry.Curve crv = g as Rhino.Geometry.Curve; Rhino.Geometry.TextDot dot = g as Rhino.Geometry.TextDot; if (pt != null) { unroll.AddFollowingGeometry(pt.Location); } else if (crv != null) { unroll.AddFollowingGeometry(crv); } else if (dot != null) { unroll.AddFollowingGeometry(dot); } } unroll.ExplodeOutput = false; Rhino.Geometry.Curve[] curves; Rhino.Geometry.Point3d[] points; Rhino.Geometry.TextDot[] dots; Rhino.Geometry.Brep[] breps = unroll.PerformUnroll(out curves, out points, out dots); if (breps == null || breps.Length < 1) { return(Rhino.Commands.Result.Failure); } for (int i = 0; i < breps.Length; i++) { doc.Objects.AddBrep(breps[i]); } for (int i = 0; i < curves.Length; i++) { doc.Objects.AddCurve(curves[i]); } doc.Objects.AddPoints(points); for (int i = 0; i < dots.Length; i++) { doc.Objects.AddTextDot(dots[i]); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Select objects to define block var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to define block"); go.ReferenceObjectSelect = false; go.SubObjectSelect = false; go.GroupSelect = true; // Phantoms, grips, lights, etc., cannot be in blocks. var forbidden_geometry_filter = Rhino.DocObjects.ObjectType.Light | Rhino.DocObjects.ObjectType.Grip | Rhino.DocObjects.ObjectType.Phantom; var geometry_filter = forbidden_geometry_filter ^ Rhino.DocObjects.ObjectType.AnyObject; go.GeometryFilter = geometry_filter; go.GetMultiple(1, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } // Block base point Rhino.Geometry.Point3d base_point; var rc = Rhino.Input.RhinoGet.GetPoint("Block base point", false, out base_point); if (rc != Rhino.Commands.Result.Success) { return(rc); } // Block definition name string idef_name = ""; rc = Rhino.Input.RhinoGet.GetString("Block definition name", false, ref idef_name); if (rc != Rhino.Commands.Result.Success) { return(rc); } // Validate block name idef_name = idef_name.Trim(); if (string.IsNullOrEmpty(idef_name)) { return(Rhino.Commands.Result.Nothing); } // See if block name already exists Rhino.DocObjects.InstanceDefinition existing_idef = doc.InstanceDefinitions.Find(idef_name, true); if (existing_idef != null) { Rhino.RhinoApp.WriteLine("Block definition {0} already exists", idef_name); return(Rhino.Commands.Result.Nothing); } // Gather all of the selected objects var geometry = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>(); var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>(); for (int i = 0; i < go.ObjectCount; i++) { var rhinoObject = go.Object(i).Object(); if (rhinoObject != null) { geometry.Add(rhinoObject.Geometry); attributes.Add(rhinoObject.Attributes); } } // Gather all of the selected objects int idef_index = doc.InstanceDefinitions.Add(idef_name, string.Empty, base_point, geometry, attributes); if (idef_index < 0) { Rhino.RhinoApp.WriteLine("Unable to create block definition", idef_name); return(Rhino.Commands.Result.Failure); } 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 Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select curves"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } for (int i = 0; i < go.ObjectCount; i++) { Rhino.Geometry.Curve curve = go.Object(i).Curve(); if (null == curve) { return(Result.Failure); } if (curve is LineCurve) { RhinoApp.WriteLine("Curve {0} is a line.", i); } else if (curve is ArcCurve) { if (curve.IsClosed) { RhinoApp.WriteLine("Curve {0} is a circle.", i); } else { RhinoApp.WriteLine("Curve {0} is an arc.", i); } } else if (curve is PolylineCurve) { RhinoApp.WriteLine("Curve {0} is a polyline.", i); } else if (curve is PolyCurve) { RhinoApp.WriteLine("Curve {0} is a polycurve.", i); } else if (curve is NurbsCurve) { if (curve.IsEllipse()) { if (curve.IsClosed) { RhinoApp.WriteLine("Curve {0} is an ellipse.", i); } else { RhinoApp.WriteLine("Curve {0} is an elliptical arc.", i); } } else { RhinoApp.WriteLine("Curve {0} is a NURBS curve.", i); } } else { RhinoApp.WriteLine("Curve {0} is an unknown type.", i); } } return(Result.Success); }
public Rhino.Commands.Result IntersectBrep(Rhino.RhinoDoc doc) { // Input interval var input = new Rhino.Input.Custom.GetNumber(); input.SetCommandPrompt("Input slicing interval"); input.Get(); if (input.CommandResult() != Rhino.Commands.Result.Success) { RhinoApp.WriteLine("Can't obtain interval number"); return(input.CommandResult()); } double SlicingInterval = input.Number(); // Select two curves to intersect var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select Brep"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; go.GetMultiple(1, 1); Rhino.Geometry.Brep brepA = null; Rhino.Geometry.Surface surfaceB = null; if (go.CommandResult() != Rhino.Commands.Result.Success) { RhinoApp.WriteLine("Can't obtain objects"); return(input.CommandResult()); } brepA = go.Object(0).Brep(); var go2 = new Rhino.Input.Custom.GetObject(); go2.SetCommandPrompt("Select surface"); go2.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go2.GetMultiple(1, 1); if (go2.CommandResult() != Rhino.Commands.Result.Success) { RhinoApp.WriteLine("Can't obtain objects"); return(input.CommandResult()); } surfaceB = go2.Object(0).Surface(); // Calculate the intersection RhinoApp.WriteLine("Executing the intersection between surfaces"); const double intersection_tolerance = 0.001; Rhino.Geometry.Curve[] intersectionCurves = null; Rhino.Geometry.Point3d[] intersectionPoints = null; bool ret = Rhino.Geometry.Intersect.Intersection.BrepSurface(brepA, surfaceB, intersection_tolerance, out intersectionCurves, out intersectionPoints); if (ret) { List <PlanePoint> PlanePoints = new List <PlanePoint>(); RhinoApp.WriteLine("Success - {0} curves", intersectionCurves.Length); for (int i = 0; i < intersectionCurves.Length; i++) { Rhino.Geometry.Curve curve = intersectionCurves[i]; doc.Objects.AddCurve(curve); RhinoApp.WriteLine("Curve is added"); Utility.CreateSections(doc, brepA, surfaceB, curve, SlicingInterval, ref PlanePoints); } RhinoApp.WriteLine("Success - {0} points", intersectionPoints.Length); for (int i = 0; i < intersectionPoints.Length; i++) { Rhino.Geometry.Point3d point = intersectionPoints[i]; doc.Objects.AddPoint(point); RhinoApp.WriteLine("Point is added"); } if (Utility.SavePlanePoints(@"c:\SlicerPlanePoints.csv", PlanePoints)) { RhinoApp.WriteLine("Saved SlicerPlanePoints.csv"); } } return(Rhino.Commands.Result.Success); }
/// <summary> /// Select object for which an area value can be calculated /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GetObjectForArea(object sender, EventArgs e) { using (Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()) { go.SetCommandPrompt(Rhino.UI.Localization.LocalizeString("Select closed curve, hatch, surface, or mesh", 359)); go.AcceptNothing(true); go.SubObjectSelect = false; go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Hatch | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh; go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve; go.DisablePreSelect(); go.Get(); if (go.CommandResult() == Rhino.Commands.Result.Success) { Rhino.DocObjects.ObjRef objref = go.Object(0); if (objref != null) { SelectedObjectId = objref.ObjectId; objref.Dispose(); } } } }