public static Result PrePostPick(RhinoDoc doc) { 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 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 Result MeshVolume(RhinoDoc doc) { var gm = new GetObject(); gm.SetCommandPrompt("Select solid meshes for volume calculation"); gm.GeometryFilter = ObjectType.Mesh; gm.GeometryAttributeFilter = GeometryAttributeFilter.ClosedMesh; gm.SubObjectSelect = false; gm.GroupSelect = true; gm.GetMultiple(1, 0); if (gm.CommandResult() != Result.Success) return gm.CommandResult(); double volume = 0.0; double volume_error = 0.0; foreach (var obj_ref in gm.Objects()) { if (obj_ref.Mesh() != null) { var mass_properties = VolumeMassProperties.Compute(obj_ref.Mesh()); if (mass_properties != null) { volume += mass_properties.Volume; volume_error += mass_properties.VolumeError; } } } RhinoApp.WriteLine("Total volume = {0:f} (+/- {1:f})", volume, volume_error); return 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 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(Rhino.RhinoDoc doc, RunMode mode) { Rhino.Input.Custom.GetObject getobjects = new Rhino.Input.Custom.GetObject(); getobjects.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; getobjects.AcceptNothing(false); switch (getobjects.GetMultiple(1, 0)) { case GetResult.ExitRhino: return(Result.ExitRhino); case GetResult.Cancel: return(Result.Cancel); case GetResult.Object: if (getobjects.ObjectCount > 1) { Rhino.DocObjects.ObjRef[] arrCurve = getobjects.Objects(); Array.Sort(arrCurve, (x, y) => x.Curve().GetLength().CompareTo(y.Curve().GetLength())); doc.Objects.Delete(arrCurve[0], true); } return(Result.Success); default: return(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 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 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 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 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); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var layerCheck = doc.Layers.FindName("CenterPoints"); if (layerCheck == null) { doc.Layers.Add("CenterPoints", System.Drawing.Color.Blue); layerCheck = doc.Layers.FindName("CenterPoints"); } //pick objects to add center point Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to add center point"); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center and add point to doc for (int i = 0; i < go.ObjectCount; i++) { Guid pointG; Rhino.DocObjects.ObjRef objref = go.Object(i); Rhino.DocObjects.RhinoObject obj = objref.Object(); var objType = obj.ObjectType; if (objType == Rhino.DocObjects.ObjectType.Curve) { Curve curve = objref.Curve(); Circle circle = new Circle(); if (!curve.TryGetCircle(out circle, doc.ModelAbsoluteTolerance)) { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; pointG = doc.Objects.AddPoint(bbObjCenter); } else { Point3d circleCenter = circle.Center; pointG = doc.Objects.AddPoint(circleCenter); } } else { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; pointG = doc.Objects.AddPoint(bbObjCenter); } Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(pointG); circObj.Attributes.LayerIndex = layerCheck.Index; circObj.CommitChanges(); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var layerCheck = doc.Layers.FindName("Numbers"); if (layerCheck == null) { doc.Layers.Add("Numbers", System.Drawing.Color.DarkRed); layerCheck = doc.Layers.FindName("Numbers"); } //pick objects to add center point Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to number"); var heightref = new Rhino.Input.Custom.OptionDouble(height); go.AddOptionDouble("Text_height_mm", ref heightref); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center and add point to doc for (int i = 0; i < go.ObjectCount; i++) { height = heightref.CurrentValue; Rhino.DocObjects.ObjRef objref = go.Object(i); Guid objGuid = objref.ObjectId; BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; int a = i + 1; Plane plane = Plane.WorldXY; plane.Origin = bbObjCenter; var Justification = TextJustification.MiddleCenter; string text = a.ToString(); var Font = "Arial"; Guid num = doc.Objects.AddText(text, plane, height, Font, false, false, Justification); Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(num); circObj.Attributes.LayerIndex = layerCheck.Index; circObj.CommitChanges(); int groupIndex = doc.Groups.Count; groupIndex++; string group = groupIndex.ToString(); var gI = doc.Groups.Add(group); doc.Groups.AddToGroup(gI, num); doc.Groups.AddToGroup(gI, objGuid); } doc.Views.Redraw(); return(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); Point3d pt1 = line1.PointAt(b); // pt0 and pt1 should be equal, so we will only add pt0 to the document doc.Objects.AddPoint(pt0); 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); Point3d pt1 = line1.PointAt(b); // pt0 and pt1 should be equal, so we will only add pt0 to the document doc.Objects.AddPoint( pt0 ); doc.Views.Redraw(); return Rhino.Commands.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 Result Loft(RhinoDoc doc) { // select curves to loft var gs = new GetObject(); gs.SetCommandPrompt("select curves to loft"); gs.GeometryFilter = ObjectType.Curve; gs.DisablePreSelect(); gs.SubObjectSelect = false; gs.GetMultiple(2, 0); if (gs.CommandResult() != Result.Success) return gs.CommandResult(); var curves = gs.Objects().Select(obj => obj.Curve()).ToList(); var breps = Brep.CreateFromLoft(curves, Point3d.Unset, Point3d.Unset, LoftType.Tight, false); foreach (var brep in breps) doc.Objects.AddBrep(brep); doc.Views.Redraw(); return Result.Success; }
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 Result EdgeSrf(RhinoDoc doc) { var go = new GetObject(); go.SetCommandPrompt("Select 2, 3, or 4 open curves"); go.GeometryFilter = ObjectType.Curve; go.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve; go.GetMultiple(2, 4); if (go.CommandResult() != Result.Success) return go.CommandResult(); var curves = go.Objects().Select(o => o.Curve()); var brep = Brep.CreateEdgeSurface(curves); if (brep != null) { doc.Objects.AddBrep(brep); doc.Views.Redraw(); } return 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 double intersection_tolerance = 0.001; 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 myTypes = ObjectType.AnyObject ^ ObjectType.BrepLoop; //pick objects to expand Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to scale"); go.GeometryFilter = myTypes; //go.GroupSelect = true; go.SubObjectSelect = true; //go.EnableClearObjectsOnEntry(false); //go.EnableUnselectObjectsOnExit(false); //go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center Point3d centersAdd = new Point3d(); for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; centers.Add(bbObjCenter); centersAdd += bbObjCenter; Rhino.DocObjects.ObjRef objref = go.Object(i); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); dynRef.Add(objref); } Point3d allCenter = centersAdd / centers.Count; //pick center GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Basepoint. Press Enter for automatic."); gp.AcceptNothing(true); var resgp = gp.Get(); if (resgp == GetResult.Nothing) { scaleCenter = allCenter; } else { scaleCenter = gp.Point(); } Rhino.Display.RhinoView view = gp.View(); plane2D = view.ActiveViewport.ConstructionPlane(); //Expansion factor GetPoint gp2 = new GetPoint(); gp2.SetCommandPrompt("Scale factor or first reference point <" + factor + ">"); gp2.DrawLineFromPoint(scaleCenter, true); gp2.AcceptNumber(true, true); GetResult gr = gp2.Get(); if (gr == GetResult.Number) { factor = gp2.Number(); } if (gr == GetResult.Point) { scaleRefPoint = gp2.Point(); Line line1 = new Line(scaleCenter, scaleRefPoint); Guid tempLine = doc.Objects.AddLine(line1); Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint); if (scaleCenter == gp2.Point()) { return(Rhino.Commands.Result.Cancel); } GetPoint gp3 = new GetPoint(); gp3.SetCommandPrompt("Secondt reference point"); gp3.AddOptionList("ScaleDimension", dimensions, 0); gp3.DrawLineFromPoint(scaleCenter, true); gp3.DynamicDraw += RefObjDraw; while (true) { GetResult res = gp3.Get(); if (res == GetResult.Option) { dimensionIndex = gp3.Option().CurrentListOptionIndex; continue; } else if (res == GetResult.Point) { Point3d scaleRefPoint2 = gp3.Point(); factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint)); doc.Objects.Delete(tempLine, true); doc.Objects.Delete(tempPoint, true); } break; } } RhinoApp.WriteLine("Scale factor: " + factor); //Compute translation //Translate 3d if (dimensionIndex == 0) { for (int i = 0; i < go.ObjectCount; i++) { var xform = Transform.Scale(centers[i], factor); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } //Translate 2d else if (dimensionIndex == 1) { for (int i = 0; i < go.ObjectCount; i++) { plane2D.Origin = centers[i]; var xform = Rhino.Geometry.Transform.Scale(plane2D, factor, factor, 1); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } //Translate 1d else if (dimensionIndex == 2) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vec = (scaleRefPoint - scaleCenter); Plane scalePlane = new Plane(centers[i], vec); var xform = Transform.Scale(scalePlane, 1, 1, factor); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } centers = new List <Point3d>(); dimensionIndex = 0; plane2D = new Plane(); dynRef = new List <Rhino.DocObjects.ObjRef>(); doc.Views.Redraw(); return(Result.Success); }
public static Rhino.Commands.Result CreateBlock(Rhino.RhinoDoc doc) { // 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.Failure; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { int currIntOption = 0; var gi = new GetOption(); gi.SetCommandPrompt("Material Index"); gi.AcceptNumber(true, true); var resgi = gi.Get(); if (resgi == GetResult.Number) { currIntOption = Convert.ToInt32(gi.Number()); } Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to apply material"); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Nothing to do - get out quick. if (go.ObjectCount == 0) { return(Result.Success); } var rm = FindMaterial(doc, matName[currIntOption]); if (null == rm) { //Didn't find the material - create one and carry on. //Create a basic material var custom = new Rhino.DocObjects.Material(); custom.Name = matName[currIntOption]; if (currIntOption == 13) { custom.SetEnvironmentTexture(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Free Jewels Rhino Plug-Ins/Dia3.jpg"); } custom.CommitChanges(); rm = RenderMaterial.CreateBasicMaterial(custom); rm.BeginChange(RenderContent.ChangeContexts.Program); rm.SetParameter("diffuse", System.Drawing.Color.Black); rm.SetParameter("reflectivity", 1.0); rm.SetParameter("reflectivity-color", System.Drawing.Color.FromArgb(r[currIntOption], g[currIntOption], b[currIntOption])); rm.SetParameter("transparency", fjMatTrans[currIntOption]); rm.SetParameter("shine", fjMatShine[currIntOption]); rm.SetParameter("polish-amount", fjMatShine[currIntOption]); rm.EndChange(); var docMats = doc.RenderMaterials; docMats.Add(rm); } //Now we always have a material to assign, this part is easy for (int i = 0; i < go.ObjectCount; i++) { var obj = go.Object(i).Object(); obj.RenderMaterial = rm; obj.CommitChanges(); } doc.Views.Redraw(); return(Result.Success); }
public static List<GH_LinearDimension> GetLinearDimensions2() { GetObject obj2; Label_0000: obj2 = new GetObject(); if (m_reference) { obj2.SetCommandPrompt("LinearDimension reference"); obj2.AddOption("Mode", "Reference"); } else { obj2.SetCommandPrompt("LinearDimension to copy"); obj2.AddOption("Mode", "Copy"); } obj2.GeometryFilter = ObjectType.Annotation; GetResult multiple = obj2.GetMultiple(1, 0); if (multiple == GetResult.Option) { m_reference = !m_reference; goto Label_0000; } if (multiple != GetResult.Object) { return null; } List<GH_LinearDimension> list2 = new List<GH_LinearDimension>(); for (int i = 0; i < obj2.ObjectCount; i++) { if (m_reference) { GH_LinearDimension dm = new GH_LinearDimension(obj2.Object(i).ObjectId); if ((dm != null) && (!dm.IsGeometryLoaded)) { dm.LoadGeometry(); } list2.Add( dm); } else { list2.Add(new GH_LinearDimension((LinearDimension)obj2.Object(i).Geometry())); } } return list2; }
//Creates reinforcement objects and saves them into the selected point as userData public static Reinforcement[] CreateReinforcements(string mName, double diam) { RhinoDoc doc = RhinoDoc.ActiveDoc; //Allow user to pick multiple objects const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject() { GeometryFilter = geometryFilter, GroupSelect = true, SubObjectSelect = false, DeselectAllBeforePostSelect = false }; go.SetCommandPrompt("Pick all the points that you want to change to reinforcement."); go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); bool bHavePreselectedObjects = false; for (;;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } //Unselects the preselected objects if (bHavePreselectedObjects) { for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int layerIndex = GetOrCreateLayer(doc, "Reinforcement", Color.Black); if (layerIndex == 999) { return new Reinforcement[] {} } ; Reinforcement[] reinfList = { }; //Create reinforcement objects for each selected points ObjRef[] objects = go.Objects(); if (objects != null) { reinfList = CreateReinfObjs(doc, objects, layerIndex, mName, diam); } return(reinfList); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { bool allBrepSolid = true; const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh; GetObject wro = new Rhino.Input.Custom.GetObject(); wro.SetCommandPrompt("Select objects to weight."); wro.GeometryFilter = geometryFilter; wro.SubObjectSelect = true; wro.DeselectAllBeforePostSelect = false; wro.OneByOnePostSelect = true; wro.GetMultiple(1, 0); double volObj3 = 0; for (int i = 0; i < wro.ObjectCount; i++) { Rhino.DocObjects.ObjRef objref = wro.Object(i); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } // get selected surface (face) Brep refcr = objref.Brep(); if (refcr != null) { var volObj = VolumeMassProperties.Compute(refcr); double volObj2 = refcr.GetVolume(); volObj3 = volObj3 + volObj2; bool brepSolid = refcr.IsSolid; if (brepSolid == false) { allBrepSolid = false; } } if (refcr == null) { Mesh refcm = objref.Mesh(); Brep refmb = Brep.CreateFromMesh(refcm, false); var volOb = VolumeMassProperties.Compute(refmb); double volObj4 = refmb.GetVolume(); volObj3 = volObj3 + volObj4; bool brepSolid = refmb.IsSolid; if (brepSolid == false) { allBrepSolid = false; } } } double gold18k = Math.Round(volObj3 * 0.0158, 2, MidpointRounding.AwayFromZero); double gold14k = Math.Round(volObj3 * 0.0146, 2, MidpointRounding.AwayFromZero); double platinum = Math.Round(volObj3 * 0.0214, 2, MidpointRounding.AwayFromZero); double palladium = Math.Round(volObj3 * 0.012, 2, MidpointRounding.AwayFromZero); double silver925 = Math.Round(volObj3 * 0.0102, 2, MidpointRounding.AwayFromZero); double diaCt = Math.Round(volObj3 * 0.01755, 2, MidpointRounding.AwayFromZero); if (allBrepSolid) { RhinoApp.WriteLine("The weight is: Gold 18k " + gold18k + "g, Gold 14k " + gold14k + "g, Platinum " + platinum + "g, Palladium " + palladium + "g, Silver 925 " + silver925 + "g, Diamond" + diaCt + "Ct"); } else { RhinoApp.WriteLine("AT LEAST ONE OBJECT IS OPEN! Result might be false!" + "The weight is: Gold 18k " + gold18k + "g, Gold 14k " + gold14k + "g, Platinum " + platinum + "g, Palladium " + palladium + "g, Silver 925 " + silver925 + "g, Diamond" + diaCt + "Ct"); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Pick all the points that you want to change to reinforcement."); go.GeometryFilter = geometryFilter; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (;;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); /* * if (res == Rhino.Input.GetResult.Option) * { * go.EnablePreSelect(false, true); * continue; * } * else if (res != Rhino.Input.GetResult.Option) * { * return Rhino.Commands.Result.Cancel; * } */ if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } List <Point3d> points = new List <Point3d>(); if (bHavePreselectedObjects) { for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int layerIndex = getLayerIndex(doc, "Reinforcement"); doc.Layers[layerIndex].Color = Color.Black; if (layerIndex == 999) { return(Result.Failure); } ObjRef[] objects = go.Objects(); foreach (ObjRef obj in objects) { Point3d point = obj.Point().Location; //TODO add the functionality how to assign different steel materials. Reinforcement reinf = new Reinforcement { Material = new SteelMaterial("B500B"), BasePoint = point, Diameter = 8 }; ObjectAttributes attr = new ObjectAttributes(); attr.UserData.Add(reinf); attr.SetUserString("Name", "Reinforcement"); attr.LayerIndex = layerIndex; //Unused code to create a hatch around the point /* * doc.Objects.AddCurve(reinf.OutLine,attr); * ObjectAttributes attrHatch = new ObjectAttributes(); * attrHatch.LayerIndex = layerIndex; * doc.Objects.AddHatch(reinf.Hatch, attrHatch); */ doc.Objects.ModifyAttributes(obj, attr, true); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { double tolerance = doc.ModelAbsoluteTolerance; List <Curve> icur = new List <Curve>(); GetObject gcr = new Rhino.Input.Custom.GetObject(); gcr.SetCommandPrompt("Select reference circles for stones. (No curves)"); gcr.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gcr.GroupSelect = true; gcr.SubObjectSelect = true; gcr.DeselectAllBeforePostSelect = true; gcr.OneByOnePostSelect = false; gcr.GetMultiple(1, 0); for (int ie = 0; ie < gcr.ObjectCount; ie++) { Rhino.DocObjects.ObjRef objref = gcr.Object(ie); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } Curve refcr = objref.Curve(); if (refcr == null) { return(Result.Failure); } obj.Select(false); icur.Add(refcr); } var rm = FindMaterial(doc, "Diamond"); if (null == rm) { //Didn't find the material - create one and carry on. //Create a basic material var custom = new Rhino.DocObjects.Material(); custom.Reflectivity = 1; custom.Transparency = 0.2; custom.SetEnvironmentTexture(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Free Jewels Rhino Plug-Ins/Dia3.jpg"); custom.Name = "Diamond"; custom.CommitChanges(); rm = RenderMaterial.CreateBasicMaterial(custom); var docMats = doc.RenderMaterials; //docMats.BeginChange(RenderContent.ChangeContexts.Program); docMats.Add(rm); //docMats.EndChange(); } // Create Stone Mesh Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); mesh.Vertices.Add(0.0, 0.0, -0.44); //0 mesh.Vertices.Add(0.0, 0.097, -0.363); //1 mesh.Vertices.Add(0.069, 0.069, -0.363); //2 mesh.Vertices.Add(0.097, 0.0, -0.363); //3 mesh.Vertices.Add(0.0, 0.5, -0.013); //4 mesh.Vertices.Add(0.098, 0.49, -0.005); //5 mesh.Vertices.Add(0.191, 0.462, -0.013); //6 mesh.Vertices.Add(0.278, 0.416, -0.005); //7 mesh.Vertices.Add(0.354, 0.354, -0.013); //8 mesh.Vertices.Add(0.416, 0.278, -0.005); //9 mesh.Vertices.Add(0.462, 0.191, -0.013); //10 mesh.Vertices.Add(0.49, 0.098, -0.005); //11 mesh.Vertices.Add(0.5, 0.0, -0.013); //12 mesh.Vertices.Add(0.0, 0.5, 0.013); //13 mesh.Vertices.Add(0.098, 0.49, 0.005); //14 mesh.Vertices.Add(0.191, 0.462, 0.013); //15 mesh.Vertices.Add(0.278, 0.416, 0.005); //16 mesh.Vertices.Add(0.354, 0.354, 0.013); //17 mesh.Vertices.Add(0.416, 0.278, 0.005); //18 mesh.Vertices.Add(0.462, 0.191, 0.013); //19 mesh.Vertices.Add(0.49, 0.098, 0.005); //20 mesh.Vertices.Add(0.5, 0.0, 0.013); //21 mesh.Vertices.Add(0.0, 0.372, 0.12); //22 mesh.Vertices.Add(0.263, 0.263, 0.12); //23 mesh.Vertices.Add(0.372, 0.0, 0.12); //24 mesh.Vertices.Add(0.263, -0.263, 0.12); //25 mesh.Vertices.Add(0.0, -0.372, 0.12); //26 mesh.Vertices.Add(-0.263, -0.263, 0.12); //27 mesh.Vertices.Add(-0.372, 0.0, 0.12); //28 mesh.Vertices.Add(-0.263, 0.263, 0.12); //29 mesh.Vertices.Add(0.109, 0.263, 0.16); //30 mesh.Vertices.Add(0.263, 0.109, 0.16); //31 mesh.Vertices.Add(0.263, -0.109, 0.16); //32 mesh.Vertices.Add(0.109, -0.263, 0.16); //33 mesh.Vertices.Add(-0.109, -0.263, 0.16); //34 mesh.Vertices.Add(-0.263, -0.109, 0.16); //35 mesh.Vertices.Add(-0.263, 0.109, 0.16); //36 mesh.Vertices.Add(-0.109, 0.263, 0.16); //37 mesh.Vertices.Add(0.0, 0.0, 0.16); //38 mesh.Faces.AddFace(0, 1, 6, 2); mesh.Faces.AddFace(0, 2, 10, 3); mesh.Faces.AddFace(1, 4, 5, 6); mesh.Faces.AddFace(2, 6, 7, 8); mesh.Faces.AddFace(2, 8, 9, 10); mesh.Faces.AddFace(3, 10, 11, 12); mesh.Faces.AddFace(4, 13, 14, 5); mesh.Faces.AddFace(5, 14, 15, 6); mesh.Faces.AddFace(6, 15, 16, 7); mesh.Faces.AddFace(7, 16, 17, 8); mesh.Faces.AddFace(8, 17, 18, 9); mesh.Faces.AddFace(9, 18, 19, 10); mesh.Faces.AddFace(10, 19, 20, 11); mesh.Faces.AddFace(11, 20, 21, 12); mesh.Faces.AddFace(13, 22, 15, 14); mesh.Faces.AddFace(15, 23, 17, 16); mesh.Faces.AddFace(17, 23, 19, 18); mesh.Faces.AddFace(19, 24, 21, 20); mesh.Faces.AddFace(15, 22, 30, 23); mesh.Faces.AddFace(19, 23, 31, 24); mesh.Faces.AddFace(23, 30, 31); mesh.Faces.AddFace(24, 31, 32); mesh.Faces.AddFace(32, 31, 30, 38); mesh.Unweld(0.001, false); Mesh meshAll = new Mesh(); for (int i = 0; i < 4; i++) { meshAll.Append(mesh); Point3d center = new Point3d(0.0, 0.0, 0.0); Vector3d rotVec = new Vector3d(0.0, 0.0, 1.0); mesh.Rotate(Math.PI / 2, rotVec, center); } meshAll.Compact(); meshAll.Weld(0.001); //Get object Guid to apply render material var meshGuid = doc.Objects.AddMesh(meshAll); ObjRef objre = new ObjRef(meshGuid); RhinoObject obje = objre.Object(); obje.RenderMaterial = rm; obje.CommitChanges(); //Make InstanceDefinition string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); var geometry = new System.Collections.Generic.List <Rhino.Geometry.GeometryBase>() { obje.Geometry }; var attributes = new System.Collections.Generic.List <Rhino.DocObjects.ObjectAttributes>() { obje.Attributes }; var stoneIndex = doc.InstanceDefinitions.Add("Stone" + instDefCount, "StoneMesh 1mm", Point3d.Origin, geometry, attributes); List <InstanceReferenceGeometry> meshPave = new List <InstanceReferenceGeometry>(); foreach (Curve c in icur) { Circle circle1 = new Circle(); c.TryGetCircle(out circle1, tolerance); double radius = circle1.Diameter; Point3d center = circle1.Center; Vector3d moveV = new Vector3d(center); Vector3d zaxis = new Vector3d(0.0, 0.0, 1.0); Plane planeOr = new Plane(center, zaxis); Plane planeNew = circle1.Plane; var transform1 = Transform.Translation(moveV); var transform2 = Transform.Scale(center, radius); var transform3 = Transform.PlaneToPlane(planeOr, planeNew); var stoneA = doc.Objects.AddInstanceObject(stoneIndex, transform1); var stoneB = doc.Objects.Transform(stoneA, transform2, true); var stoneC = doc.Objects.Transform(stoneB, transform3, true); ids.Add(stoneC); } doc.Groups.Add(ids); doc.Objects.Delete(obje); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //select the cross-section faces var gc = new Rhino.Input.Custom.GetObject(); gc.SetCommandPrompt("Select the surfaces which form the cross-section of the beam."); gc.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gc.EnablePreSelect(false, true); gc.GetMultiple(1, 1); if (gc.CommandResult() != Rhino.Commands.Result.Success) { return(gc.CommandResult()); } var face = gc.Object(0).Face(); //for each cross-section, get the base-surface curve var gv = new Rhino.Input.Custom.GetObject(); gv.SetCommandPrompt("Select the base_curve."); gv.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gv.EnablePreSelect(false, true); gv.GetMultiple(1, 1); if (gv.CommandResult() != Rhino.Commands.Result.Success) { return(gv.CommandResult()); } var base_curve = gv.Object(0).Curve(); //List of all the sub section List <Brep> sub_sections = new List <Brep>(); for (int i = 0; i < 10; i++) { //offset the base to form a closed loop var curves = base_curve.OffsetOnSurface(face, 0.1, doc.ModelAbsoluteTolerance); if (curves.Length > 1) { Rhino.RhinoApp.WriteLine("More than one offset"); return(Result.Failure); } var offset_curve = curves[0]; //connect the curves in a closed loop LineCurve edge1 = new LineCurve(base_curve.PointAtStart, offset_curve.PointAtStart); LineCurve edge2 = new LineCurve(offset_curve.PointAtEnd, base_curve.PointAtEnd); List <Curve> prejoin = new List <Curve>(); prejoin.Add(edge1); prejoin.Add(edge2); prejoin.Add(base_curve); prejoin.Add(offset_curve); var loops = Curve.JoinCurves(prejoin, doc.ModelAbsoluteTolerance); if (loops.Length > 1) { Rhino.RhinoApp.WriteLine("More than one joined loops"); return(Result.Failure); } var loop = loops[0]; var breps = Rhino.Geometry.Brep.CreatePlanarBreps(loop); if (breps.Length > 1) { Rhino.RhinoApp.WriteLine("More than one joined loops"); return(Result.Failure); } sub_sections.Add(breps[0]); doc.Objects.AddBrep(breps[0]); doc.Views.Redraw(); base_curve = offset_curve; } //compute moment of inertia var area_properties1 = Rhino.Geometry.AreaMassProperties.Compute(sub_sections); var area_properties2 = Rhino.Geometry.AreaMassProperties.Compute(face); //check for the difference Rhino.RhinoApp.WriteLine("Area {0}", area_properties1.Area); Rhino.RhinoApp.WriteLine("Difference in Area {0}", area_properties1.Area - area_properties2.Area); Rhino.RhinoApp.WriteLine("Moment X: {0}; Y: {1}; Z: {2} in WCS ", area_properties1.WorldCoordinatesMomentsOfInertia.X, area_properties1.WorldCoordinatesMomentsOfInertia.Y, area_properties1.WorldCoordinatesMomentsOfInertia.Z); Rhino.RhinoApp.WriteLine("Difference in Moment X: {0}; Y: {1}; Z: {2} in WCS", area_properties1.WorldCoordinatesMomentsOfInertia.X - area_properties2.WorldCoordinatesMomentsOfInertia.X, area_properties1.WorldCoordinatesMomentsOfInertia.Y - area_properties2.WorldCoordinatesMomentsOfInertia.Y, area_properties1.WorldCoordinatesMomentsOfInertia.Z - area_properties2.WorldCoordinatesMomentsOfInertia.Z); //display the centroids doc.Objects.AddPoint(area_properties1.Centroid); doc.Objects.AddPoint(area_properties2.Centroid); doc.Views.Redraw(); return(Result.Success); }
public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc) { // Select objects to orient Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to orient"); go.SubObjectSelect = false; go.GroupSelect = true; go.GetMultiple(1, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) return go.CommandResult(); // Point to orient from Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Point to orient from"); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); // Define source plane Rhino.Display.RhinoView view = gp.View(); if (view == null) { view = doc.Views.ActiveView; if (view == null) return Rhino.Commands.Result.Failure; } Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane(); source_plane.Origin = gp.Point(); // Surface to orient on Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject(); gs.SetCommandPrompt("Surface to orient on"); gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gs.SubObjectSelect = true; gs.DeselectAllBeforePostSelect = false; gs.OneByOnePostSelect = true; gs.Get(); if (gs.CommandResult() != Rhino.Commands.Result.Success) return gs.CommandResult(); Rhino.DocObjects.ObjRef objref = gs.Object(0); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) return Rhino.Commands.Result.Failure; // get selected surface (face) Rhino.Geometry.Surface surface = objref.Surface(); if (surface == null) return Rhino.Commands.Result.Failure; // Unselect surface obj.Select(false); // Point on surface to orient to gp.SetCommandPrompt("Point on surface to orient to"); gp.Constrain(surface, false); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); // Do transformation Rhino.Commands.Result rc = Rhino.Commands.Result.Failure; double u, v; if (surface.ClosestPoint(gp.Point(), out u, out v)) { Rhino.Geometry.Plane target_plane; if (surface.FrameAt(u, v, out target_plane)) { // Build transformation Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane); // Do the transformation. In this example, we will copy the original objects 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 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) { //pick objects to expand Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to expand"); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center Point3d centersAdd = new Point3d(); for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; centers.Add(bbObjCenter); centersAdd += bbObjCenter; Rhino.DocObjects.ObjRef objref = go.Object(i); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); goList.Add(obj); } Point3d allCenter = centersAdd / centers.Count; //pick center GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Basepoint. Press Enter for automatic."); gp.AcceptNothing(true); var resgp = gp.Get(); if (resgp == GetResult.Nothing) { scaleCenter = allCenter; } else { scaleCenter = gp.Point(); } //Expansion factor GetPoint gp2 = new GetPoint(); gp2.SetCommandPrompt("Expansion factor or first reference point <" + factor + ">"); gp2.DrawLineFromPoint(scaleCenter, true); gp2.AcceptNumber(true, true); GetResult gr = gp2.Get(); Rhino.Display.RhinoView view = gp2.View(); plane2D = view.ActiveViewport.ConstructionPlane(); if (gr == GetResult.Number) { factor = gp2.Number(); } if (gr == GetResult.Point) { scaleRefPoint = gp2.Point(); Line line1 = new Line(scaleCenter, scaleRefPoint); Guid tempLine = doc.Objects.AddLine(line1); Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint); if (scaleCenter == gp2.Point()) { return(Rhino.Commands.Result.Cancel); } GetPoint gp3 = new GetPoint(); gp3.SetCommandPrompt("Secondt reference point"); gp3.AddOptionList("ScaleDimension", dimensions, 0); gp3.DrawLineFromPoint(scaleCenter, true); gp3.DynamicDraw += RefObjDraw; while (true) { GetResult res = gp3.Get(); if (res == GetResult.Option) { dimensionIndex = gp3.Option().CurrentListOptionIndex; continue; } else if (res == GetResult.Point) { Point3d scaleRefPoint2 = gp3.Point(); factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint)); doc.Objects.Delete(tempLine, true); doc.Objects.Delete(tempPoint, true); } break; } } RhinoApp.WriteLine("Expantion factor: " + factor); //Compute translation //Translate 3d if (dimensionIndex == 0) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vec = (centers[i] - scaleCenter) * (factor - 1); var xform = Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } //Translate 2d else if (dimensionIndex == 1) { for (int i = 0; i < go.ObjectCount; i++) { Rhino.Geometry.Vector3d vec = (centers[i] - scaleCenter) * (factor - 1); Vector3d planeNormal = plane2D.Normal; if (planeNormal[0] != 0) { vec.X = 0; } else if (planeNormal[1] != 0) { vec.Y = 0; } else if (planeNormal[2] != 0) { vec.Z = 0; } var xform = Rhino.Geometry.Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } //Translate 1d else if (dimensionIndex == 2) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vecEach = (centers[i] - scaleCenter); double vecEachLength = vecEach.Length * (factor - 1); Vector3d vec = (scaleRefPoint - scaleCenter); double angleVec = Vector3d.VectorAngle(vecEach, vec); int pol = 1; if (angleVec > 1.57) { pol = -1; } vec.Unitize(); vec = vec * vecEachLength * pol; var xform = Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } goList = new List <Object>(); centers = new List <Point3d>(); dimensionIndex = 0; plane2D = new Plane(); doc.Views.Redraw(); return(Result.Success); }
public static Rhino.Commands.Result CreateBlock(Rhino.RhinoDoc doc) { // 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. const ObjectType forbidden_geometry_filter = Rhino.DocObjects.ObjectType.Light | Rhino.DocObjects.ObjectType.Grip | Rhino.DocObjects.ObjectType.Phantom; const ObjectType 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.Failure); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. var 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 the cross-section faces var gb = new Rhino.Input.Custom.GetObject(); gb.SetCommandPrompt("Select the surfaces which form the cross-section of the beam."); gb.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gb.EnablePreSelect(false, true); gb.GetMultiple(1, 0); if (gb.CommandResult() != Rhino.Commands.Result.Success) { return(gb.CommandResult()); } List <BrepFace> cross_section = new List <BrepFace>(); for (int i = 0; i < gb.ObjectCount; i++) { var face = gb.Object(i).Face(); if (face != null) { cross_section.Add(face); } } //select the rail 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); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { double tolerance = doc.ModelAbsoluteTolerance; List <Curve> icur = new List <Curve>(); GetObject gcr = new Rhino.Input.Custom.GetObject(); gcr.SetCommandPrompt("Select reference circles for drill. (No curves)"); gcr.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gcr.GroupSelect = true; gcr.SubObjectSelect = true; gcr.DeselectAllBeforePostSelect = true; gcr.OneByOnePostSelect = false; gcr.GetMultiple(1, 0); for (int ie = 0; ie < gcr.ObjectCount; ie++) { Rhino.DocObjects.ObjRef objref = gcr.Object(ie); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } Curve refcr = objref.Curve(); if (refcr == null) { return(Result.Failure); } obj.Select(false); icur.Add(refcr); } while (true) { m_escape_key_pressed = false; RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed; List <Curve> curveDrill = new List <Curve>(); Point3d centerTop = new Point3d(0, 0, (headDrill + topDrill) * drillScale); Circle circleTop = new Circle(centerTop, ancheadDrill / 2 * drillScale); Curve curveTop = circleTop.ToNurbsCurve(); curveDrill.Add(curveTop); Point3d centerMid = new Point3d(0, 0, topDrill * drillScale); Circle circleMid = new Circle(centerMid, drillScale / 2); Curve curveMid = circleMid.ToNurbsCurve(); curveDrill.Add(curveMid); Circle circleBase = new Circle(drillScale / 2); Curve curveBase = circleBase.ToNurbsCurve(); curveDrill.Add(curveBase); Point3d centerLow = new Point3d(0, 0, -midDrill * drillScale); Circle circleLow = new Circle(centerLow, ancDrill / 2 * drillScale); Curve curveLow = circleLow.ToNurbsCurve(); curveDrill.Add(curveLow); if (bottDrill != 0) { Point3d centerBot = new Point3d(0, 0, (-midDrill - bottDrill) * drillScale); Circle circleBot = new Circle(centerBot, ancDrill / 2 * drillScale); Curve curveBot = circleBot.ToNurbsCurve(); curveDrill.Add(curveBot); } Brep[] cylBrep1 = Brep.CreateFromLoft(curveDrill, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); Brep[] cylBrep2 = Brep.CreateBooleanUnion(cylBrep1, tolerance); Brep cylBrepFinal = cylBrep1[0]; cylBrepFinal = cylBrepFinal.CapPlanarHoles(tolerance); string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); Brep[] brepArray = new Brep[1] { cylBrepFinal }; var drillIndex = doc.InstanceDefinitions.Add("Drill" + instDefCount, "RefDrill 1mm", Point3d.Origin, brepArray); foreach (Curve c in icur) { Circle circleDrill = new Circle(); c.TryGetCircle(out circleDrill, tolerance); double radiusDrill = circleDrill.Diameter; Point3d center = circleDrill.Center; Vector3d moveV = new Vector3d(center); Vector3d zaxis = new Vector3d(0.0, 0.0, 1.0); Plane planeOr = new Plane(center, zaxis); Plane planeNew = circleDrill.Plane; var transform1 = Transform.Translation(moveV); var transform2 = Transform.Scale(center, radiusDrill); var transform3 = Transform.PlaneToPlane(planeOr, planeNew); var stoneA = doc.Objects.AddInstanceObject(drillIndex, transform1); var stoneB = doc.Objects.Transform(stoneA, transform2, true); var stoneC = doc.Objects.Transform(stoneB, transform3, true); ids.Add(stoneC); doc.Views.Redraw(); } GetOption go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Set drill parameters."); go.AcceptNothing(true); var drillHead = new Rhino.Input.Custom.OptionDouble(headDrill); var drillAncHead = new Rhino.Input.Custom.OptionDouble(ancheadDrill); var drillTop = new Rhino.Input.Custom.OptionDouble(topDrill); var drillMid = new Rhino.Input.Custom.OptionDouble(midDrill); var drillAnc = new Rhino.Input.Custom.OptionDouble(ancDrill); var drillBott = new Rhino.Input.Custom.OptionDouble(bottDrill); var scaleDrill = new Rhino.Input.Custom.OptionDouble(drillScale); go.AddOptionDouble("Top", ref drillHead); go.AddOptionDouble("TopAngle", ref drillAncHead); go.AddOptionDouble("Mid", ref drillTop); go.AddOptionDouble("Bottom", ref drillMid); go.AddOptionDouble("BottomAngle", ref drillAnc); go.AddOptionDouble("Tail", ref drillBott); go.AddOptionDouble("Scale", ref scaleDrill); GetResult res = go.Get(); if (m_escape_key_pressed) { break; } topDrill = drillTop.CurrentValue; midDrill = drillMid.CurrentValue; ancDrill = drillAnc.CurrentValue; bottDrill = drillBott.CurrentValue; drillScale = scaleDrill.CurrentValue; headDrill = drillHead.CurrentValue; ancheadDrill = drillAncHead.CurrentValue; if (res == GetResult.Nothing) { break; } doc.Objects.Delete(ids, true); } RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed; doc.Groups.Add(ids); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { double tolerance = doc.ModelAbsoluteTolerance; double angleTolerance = doc.ModelAngleToleranceRadians; List <Curve> icur = new List <Curve>(); GetObject gcr = new Rhino.Input.Custom.GetObject(); gcr.SetCommandPrompt("Select reference circles for prongs. (No curves)"); gcr.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gcr.GroupSelect = true; gcr.SubObjectSelect = true; gcr.DeselectAllBeforePostSelect = true; gcr.OneByOnePostSelect = false; gcr.GetMultiple(1, 0); for (int ie = 0; ie < gcr.ObjectCount; ie++) { Rhino.DocObjects.ObjRef objref = gcr.Object(ie); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } Curve refcr = objref.Curve(); if (refcr == null) { return(Result.Failure); } obj.Select(false); icur.Add(refcr); } while (true) { m_escape_key_pressed = false; RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed; Point3d pt0 = new Point3d(0, 0, hight); Point3d pt1 = new Point3d(0, 0, -(length - hight)); double rotationRadiant = ((rotation / 180) * 3.1415); List <Point3d> curvePoints = new List <Point3d>() { pt0, pt1 }; Curve prongCurve = Curve.CreateInterpolatedCurve(curvePoints, 3); if (!capBool) { capMode = PipeCapMode.Flat; } else if (capBool) { capMode = PipeCapMode.Round; } Brep[] cylBrep1 = Brep.CreatePipe(prongCurve, prongDia / 2, false, capMode, false, tolerance, angleTolerance); Brep cylBrep2 = cylBrep1[0]; cylBrep2.Faces.RemoveAt(2); Brep cylBrep3 = cylBrep2.CapPlanarHoles(tolerance); if (capBool) { Vector3d scaleVec = new Vector3d(0, 0, 1); var scalePlane = new Plane(pt0, scaleVec); var capScale = Transform.Scale(scalePlane, 1.0, 1.0, capHight); var surf2 = cylBrep3.Faces[1].UnderlyingSurface(); NurbsSurface nurbSurf2 = surf2.ToNurbsSurface(); nurbSurf2.Transform(capScale); Brep capBrep = nurbSurf2.ToBrep(); cylBrep3.Append(capBrep); cylBrep3.Faces.RemoveAt(1); } cylBrep3.Compact(); cylBrep3.JoinNakedEdges(tolerance); string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); Brep[] brepArray = new Brep[1] { cylBrep3 }; var prongIndex = doc.InstanceDefinitions.Add("Prong" + instDefCount, "RefProng", Point3d.Origin, brepArray); foreach (Curve c in icur) { Circle circleProngs = new Circle(); c.TryGetCircle(out circleProngs, tolerance); NurbsCurve curveProngs = circleProngs.ToNurbsCurve(); Plane planeNew = circleProngs.Plane; Vector3d plVec = planeNew.Normal; if (planeNew == null) { curveProngs.DivideByCount(3, true, out Point3d[] curveProngsPoints); planeNew = new Plane(curvePoints[0], curveProngsPoints[1], curveProngsPoints[2]); } Curve[] offsetCurveArray = curveProngs.Offset(planeNew, prongDia / 4, tolerance, CurveOffsetCornerStyle.Sharp); Curve offsetCurve = offsetCurveArray[0]; double[] segParameters = offsetCurve.DivideByCount(prongCount, true); List <Point3d> prongPoints = new List <Point3d>(); List <Guid> idsInter = new List <Guid>(); foreach (double p in segParameters) { Point3d zen = new Point3d(0, 0, 0); Point3d prongPoint = offsetCurve.PointAt(p); Point3d center = circleProngs.Center; Vector3d moveV = new Vector3d(prongPoint); Vector3d zaxis = new Vector3d(0.0, 0.0, 1.0); Plane planeOr = new Plane(zen, zaxis); Plane plane = new Plane(prongPoint, plVec); var transform1 = Transform.PlaneToPlane(planeOr, plane); var transform2 = Transform.Rotation(rotationRadiant, plVec, center); var prongA = doc.Objects.AddInstanceObject(prongIndex, transform1); var prongB = doc.Objects.Transform(prongA, transform2, true); ids.Add(prongB); } doc.Views.Redraw(); } GetOption go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Set prong parameters."); go.AcceptNothing(true); var countProng = new Rhino.Input.Custom.OptionInteger(prongCount); var diaProng = new Rhino.Input.Custom.OptionDouble(prongDia); var hightProng = new Rhino.Input.Custom.OptionDouble(hight); var lengthProng = new Rhino.Input.Custom.OptionDouble(length); var rotProng = new Rhino.Input.Custom.OptionDouble(rotation); var capProng = new Rhino.Input.Custom.OptionToggle(capBool, "Flat", "Round"); var hightCap = new Rhino.Input.Custom.OptionDouble(capHight); go.AddOptionInteger("Count", ref countProng); go.AddOptionDouble("Diameter", ref diaProng); go.AddOptionDouble("Hight", ref hightProng); go.AddOptionDouble("Length", ref lengthProng); go.AddOptionDouble("Rotation", ref rotProng); go.AddOptionToggle("Cap", ref capProng); if (capBool) { go.AddOptionDouble("Caphight", ref hightCap); } GetResult res = go.Get(); if (m_escape_key_pressed) { break; } hight = hightProng.CurrentValue; length = lengthProng.CurrentValue; prongCount = countProng.CurrentValue; prongDia = diaProng.CurrentValue; rotation = rotProng.CurrentValue; capBool = capProng.CurrentValue; capHight = hightCap.CurrentValue; if (length <= 0.0) { length = 1.0; } if (prongCount <= 0) { prongCount = 1; } if (prongDia <= 0.0) { prongDia = 1.0; } if (res == GetResult.Nothing) { break; } doc.Objects.Delete(ids, true); } RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed; doc.Groups.Add(ids); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { List <Rhino.Geometry.Mesh> meshes = new List <Rhino.Geometry.Mesh>(); try { string ogre_bin = System.Environment.GetEnvironmentVariable("OGRE_HOME"); #if DEBUG ogre_bin += @"\bin\Debug"; #else ogre_bin += @"\bin\Release"; #endif string path = System.Environment.GetEnvironmentVariable("PATH"); System.Environment.SetEnvironmentVariable("PATH", path + ";" + ogre_bin, EnvironmentVariableTarget.Process); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); OptionToggle export_as_xml = new OptionToggle(false, "No", "Yes"); go.AddOptionToggle("export_as_xml", ref export_as_xml); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GeometryFilter = geometryFilter; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (; ;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); if (res == Rhino.Input.GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != Rhino.Input.GetResult.Object) { RhinoLogger.Info("Canceled."); return(Rhino.Commands.Result.Cancel); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } SaveFileDialog sv = new SaveFileDialog(); if (!export_as_xml.CurrentValue) { sv.Filter = "Mesh files (*.mesh)|*.mesh"; sv.DefaultExt = "mesh"; } else { sv.Filter = "XML files (*.xml)|*.xml"; sv.DefaultExt = "xml"; } sv.Title = "Select File to Export :"; if (sv.ShowDialog() != System.Windows.Forms.DialogResult.OK) { RhinoLogger.Info("Canceled."); return(Result.Cancel); } if (bHavePreselectedObjects) { // Normally when command finishes, pre-selected objects will remain // selected, when and post-selected objects will be unselected. // With this sample, it is possible to have a combination of // pre-selected and post-selected objects. To make sure everything // "looks the same", unselect everything before finishing the command. for (int i = 0; i < go.ObjectCount; i++) { Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int objectCount = go.ObjectCount; Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount); for (int i = 0; i < objectCount; i++) { var objref = go.Object(i); if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Mesh) { meshes.Add(objref.Mesh()); } else if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Brep) { var ms = CheckOrCreateMesh(objref.Brep(), RhinoDoc.ActiveDoc.GetMeshingParameters(MeshingParameterStyle.Custom)); meshes.AddRange(ms); } else { RhinoLogger.ErrorFormat("selection is unexpected ObjectType : {0}", objref.Geometry().ObjectType); return(Result.Failure); } } var exporter = new ExportToOgreMesh(); var exp_path = exporter.Export(sv.FileName, meshes); if (!export_as_xml.CurrentValue) { exporter.ConvertXmlToMesh(exp_path); } } catch (Exception e) { RhinoLogger.Fatal(e); return(Result.Failure); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter; Rhino.DocObjects.ObjRef objref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select first/main polysurface or surface to bool", false, geometryFilter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } if (objref == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Brep brep = objref.Brep(); bool resIssolid = brep.IsSolid; if (!resIssolid) { Dialogs.ShowMessage("Your polysurface or surface is not solid! Result might not be valid!", "Warning!"); } Guid firstBrep = objref.ObjectId; doc.Objects.UnselectAll(true); //Select rest of polysurfaces or surfaces to bool Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select rest of polysurfaces or surfaces to bool"); go.GeometryFilter = geometryFilter | Rhino.DocObjects.ObjectType.InstanceReference; go.GroupSelect = true; go.GetMultiple(1, 0); bool isSolid = true; //Add set to breps list List <Rhino.Geometry.Brep> breps = new List <Rhino.Geometry.Brep>(); for (int i = 0; i < go.ObjectCount; i++) { //Explode if instance object and add to breps list if (go.Object(i).Object() is InstanceObject) { InstanceObject instObj = go.Object(i).Object() as InstanceObject; RhinoObject[] explodedObjects; ObjectAttributes[] attributesOfExplodedObjects; Transform[] transformOfExplodedObjects; instObj.Explode(false, out explodedObjects, out attributesOfExplodedObjects, out transformOfExplodedObjects); Guid addedObjectID = doc.Objects.Add(explodedObjects[0].Geometry, explodedObjects[0].Attributes); ObjRef objrefs = new Rhino.DocObjects.ObjRef(addedObjectID); Rhino.Geometry.Brep brepd = objrefs.Brep(); brepd.Transform(transformOfExplodedObjects[0]); resIssolid = brepd.IsSolid; if (!resIssolid) { isSolid = false; } if (brepd != null && firstBrep != addedObjectID) { breps.Add(brepd); } doc.Objects.Delete(addedObjectID, true); } else { Rhino.DocObjects.ObjRef objrefs = go.Object(i); Rhino.Geometry.Brep brepd = objrefs.Brep(); resIssolid = brepd.IsSolid; if (!resIssolid) { isSolid = false; } if (brepd != null && firstBrep != objrefs.ObjectId) { breps.Add(brepd); } } } if (!isSolid) { Dialogs.ShowMessage("At least on polysurface or surface to subtract is not solid! Result might not be valid!", "Warning!"); } doc.Objects.UnselectAll(true); //Create layers for failed and successfull booleans if not already existing var fail_layer_index = doc.Layers.FindName("FJ Boolean Fails"); if (fail_layer_index == null) { string name_fail_layer = "FJ Boolean Fails"; Rhino.DocObjects.Layer boolFail = new Rhino.DocObjects.Layer(); boolFail.Name = name_fail_layer; boolFail.Color = System.Drawing.Color.Red; doc.Layers.Add(boolFail); fail_layer_index = doc.Layers.FindName(name_fail_layer); } var done_layer_index = doc.Layers.FindName("FJ Boolean Done"); if (done_layer_index == null) { string name_done_layer = "FJ Boolean Done"; Rhino.DocObjects.Layer boolDone = new Rhino.DocObjects.Layer(); boolDone.Name = name_done_layer; boolDone.Color = System.Drawing.Color.BlueViolet; doc.Layers.Add(boolDone); done_layer_index = doc.Layers.FindName(name_done_layer); } //Compute boolean union double tolerance = doc.ModelAbsoluteTolerance; int a = 0; for (int i = 0; i < breps.Count; i++) { RhinoApp.WriteLine("computing number: " + i + " of: " + breps.Count + " operations..."); List <Brep> brepBool = new List <Brep>(); brepBool.Add(brep); brepBool.Add(breps[i]); Rhino.Geometry.Brep[] brepBoolNew = Rhino.Geometry.Brep.CreateBooleanUnion(brepBool, tolerance, true); if (brepBoolNew == null || brepBoolNew.Length > 1) { a++; doc.Objects.Delete(go.Object(i).Object()); var boolresultfail = doc.Objects.AddBrep(breps[i]); ObjRef objFailref = new ObjRef(boolresultfail); Rhino.DocObjects.RhinoObject objFail = objFailref.Object(); objFail.Attributes.LayerIndex = fail_layer_index.Index; objFail.CommitChanges(); } else { brep = brepBoolNew[0]; doc.Objects.Delete(go.Object(i).Object()); var boolresult = doc.Objects.AddBrep(breps[i]); ObjRef obj20ref = new ObjRef(boolresult); Rhino.DocObjects.RhinoObject obj2Org = obj20ref.Object(); obj2Org.Attributes.LayerIndex = done_layer_index.Index; obj2Org.CommitChanges(); } doc.Views.Redraw(); } RhinoApp.WriteLine(a + " of " + breps.Count + " operations failed!"); Rhino.DocObjects.RhinoObject obj1Org = objref.Object(); doc.Objects.Delete(obj1Org); doc.Objects.AddBrep(brep); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }