public static Rhino.Geometry.Point3d getRefPoint() { Guid docBoxID = new Guid(utils.properties.tryGetDocBox()); Rhino.DocObjects.ObjRef docBox = new Rhino.DocObjects.ObjRef(docBoxID); Rhino.Geometry.Curve docBoxCurve = docBox.Curve(); List <double> xVals = new List <double>(); List <double> yVals = new List <double>(); int spanCount = docBoxCurve.SpanCount; for (int i = 0; i < spanCount; i++) { double activeParameter = docBoxCurve.SpanDomain(i).Min; Rhino.Geometry.Point3d activePoint = docBoxCurve.PointAt(activeParameter); double activeX = activePoint.X; xVals.Add(activeX); double activeY = activePoint.Y; yVals.Add(activeY); } xVals.Sort(); yVals.Sort(); Rhino.Geometry.Point3d docBoxRefPoint = new Rhino.Geometry.Point3d(xVals[0], yVals[spanCount - 1], 0); return(docBoxRefPoint); }
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); }
//Update illustrator doc bound if docbox changes in rhino. public static void docBoxChanges(Rhino.DocObjects.RhinoObject docBox) { //Parse rectangle from incoming RhinoObject. Guid incomingGuid = docBox.Id; Rhino.Geometry.Curve newCurve = null; Rhino.DocObjects.ObjRef oRef = new Rhino.DocObjects.ObjRef(incomingGuid); newCurve = oRef.Curve(); Rhino.Geometry.BoundingBox newDimsBox = newCurve.GetBoundingBox(false); Rhino.Geometry.Point3d newMinPoint = newDimsBox.Min; Rhino.Geometry.Point3d newMaxPoint = newDimsBox.Max; double newWidth = newMaxPoint.X - newMinPoint.X; double newHeight = newMaxPoint.Y - newMinPoint.Y; int conversion = utils.units.conversion(); //Compare previous size, or record if first run. string D01_Path = utils.file_structure.getPathFor("D01"); string jsxPath = utils.file_structure.getJavascriptPath(); if (System.IO.File.Exists(D01_Path) == false) { string newData = newWidth.ToString() + "|" + newHeight.ToString(); System.IO.File.WriteAllText(D01_Path, newData); } else if (System.IO.File.Exists(D01_Path) == true) { //If file exists, verify bounds changed. (Otherwise, box moved.) string[] oldData = System.IO.File.ReadAllText(D01_Path).Split('|'); double oldWidth = Convert.ToDouble(oldData[0]); double oldHeight = Convert.ToDouble(oldData[1]); //utils.debug.ping(0, "Width change: " + newWidth.ToString() + " - " + oldWidth.ToString()); if (oldWidth == newWidth && oldHeight == newHeight) { //outbound.push.fullReset(); } else { string newData = newWidth.ToString() + "|" + newHeight.ToString(); System.IO.File.WriteAllText(D01_Path, newData); echo.interop echo = new echo.interop(); echo.docBounds(newWidth, newHeight, conversion, jsxPath); //outbound.push.fullReset(); } } }
public static string tryGetDocBox() { string D10_Path = file_structure.getPathFor("D10"); if (delta_states.getGeoDeltaState() == 3) { string docBoxGUID = System.IO.File.ReadAllText(D10_Path); return(docBoxGUID); } else { if (System.IO.File.Exists(D10_Path) == false) { string docBoxGUID = makeDocBox(); return(docBoxGUID); } else if (System.IO.File.Exists(D10_Path) == true) { //If docBox has already been created, get GUID. string docBoxGUID = System.IO.File.ReadAllText(D10_Path); Guid searchGuid = new Guid(docBoxGUID); Rhino.DocObjects.ObjRef docBox = new Rhino.DocObjects.ObjRef(searchGuid); try { string test = docBox.Curve().ToString(); return(docBoxGUID); } catch (Exception e) { string guid = makeDocBox(); return(guid); } finally { //? } } } return("error"); }
/// <summary> /// Rhino calls this function to remake objects when inputs have changed. /// </summary> protected override bool ReplayHistory(Rhino.DocObjects.ReplayHistoryData replay) { Rhino.DocObjects.ObjRef objref = null; int segmentCount = 0; int pointCount = 0; if (!ReadHistory(replay, ref objref, ref segmentCount, ref pointCount)) { return(false); } Rhino.Geometry.Curve curve = objref.Curve(); if (null == curve) { return(false); } if (pointCount != replay.Results.Length) { return(false); } Rhino.Geometry.Point3d[] points; curve.DivideByCount(segmentCount, true, out points); if (null == points) { return(false); } for (int i = 0; i < points.Length; i++) { replay.Results[i].UpdateToPoint(points[i], null); } return(true); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { int counter = 0; GetObject go = new GetObject(); go.SetCommandPrompt("Select curves to offset."); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GroupSelect = true; go.SubObjectSelect = true; go.DeselectAllBeforePostSelect = true; go.OneByOnePostSelect = false; go.GetMultiple(1, 0); GetOption gop = new GetOption(); var dist = new Rhino.Input.Custom.OptionDouble(distVal); gop.SetCommandPrompt("Set values. Press enter when done."); gop.AddOptionDouble("Distance", ref dist); int optList = gop.AddOptionList("CornerStyle", corners, cornerIndex); gop.AcceptNothing(true); while (true) { if (gop.Get() == GetResult.Nothing) { break; } else if (gop.OptionIndex() == optList) { cornerIndex = gop.Option().CurrentListOptionIndex; } else { distVal = dist.CurrentValue; } } for (int i = 0; i < go.ObjectCount; i++) { Rhino.DocObjects.ObjRef objref = go.Object(i); var curve = objref.Curve(); if (curve == null) { return(Result.Nothing); } Plane plane; if (!curve.TryGetPlane(out plane)) { curve.DivideByCount(3, true, out Point3d[] curvePoints); plane = new Plane(curvePoints[0], curvePoints[1], curvePoints[2]); } try { var curves = curve.Offset(plane, distVal, doc.ModelAbsoluteTolerance, cornerStyle[cornerIndex]); foreach (var offsetcurve in curves) { doc.Objects.AddCurve(offsetcurve); } } catch { counter++; } } if (counter > 0) { RhinoApp.WriteLine(counter + " out of " + go.ObjectCount + " offset values were out of scope!"); } doc.Views.Redraw(); // --- return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { double tolerance = doc.ModelAbsoluteTolerance; List <Curve> curves = new List <Curve>(); //Select surface GetObject gs = new Rhino.Input.Custom.GetObject(); gs.SetCommandPrompt("Surface to orient on"); gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gs.SubObjectSelect = true; gs.DeselectAllBeforePostSelect = true; gs.OneByOnePostSelect = true; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } Rhino.DocObjects.ObjRef objref_Surface = gs.Object(0); Rhino.DocObjects.RhinoObject obj = objref_Surface.Object(); if (obj == null) { return(Result.Failure); } surface = objref_Surface.Surface(); if (surface == null) { return(Result.Failure); } obj.Select(false); //Select Line(s) GetObject gl = new GetObject(); gl.SetCommandPrompt("Select one or two line(s)"); gl.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gl.DeselectAllBeforePostSelect = true; gl.OneByOnePostSelect = true; gl.GetMultiple(1, 0); for (int i = 0; i < gl.ObjectCount; i++) { Rhino.DocObjects.ObjRef objref_Line = gl.Object(i); curve = objref_Line.Curve(); Curve curveRe = curve.Rebuild(60, 3, true); curves.Add(curveRe); } List <Guid> cir_guid_list = new List <Guid>(); if (curves.Count > 1) { Curve curve2 = curves[0]; Curve curve3 = curves[1]; if (curve2.IsClosed || curve3.IsClosed) { Rhino.UI.Dialogs.ShowMessage("Please only select open curves for two line pave.", "Warning!"); return(Result.Failure); } while (true) { cir_guid_list = new List <Guid>(); var tweenCurves = Curve.CreateTweenCurvesWithSampling(curve2, curve3, 1, 30, tolerance); Curve tCurve = tweenCurves[0]; //3 point circle Point3d po1 = curve2.PointAtStart; Point3d po2 = curve3.PointAtStart; LineCurve line1 = new LineCurve(po1, po2); double[] param = line1.DivideByCount(2, false); double param1 = param[0]; double param2 = param[0]; double param3 = param[0]; Curve curve1 = line1; while (true) { Circle outCircle = Circle.TryFitCircleTTT(curve1, curve2, curve3, param1, param2, param3); //circle normal to surface Point3d outCircleCenter = outCircle.Center; double outCircleRadius = outCircle.Radius; double u, v; surface.ClosestPoint(outCircleCenter, out u, out v); var direction = surface.NormalAt(u, v); Point3d surfCenter = surface.PointAt(u, v); Plane pl1 = new Plane(surfCenter, direction); Circle circle = new Circle(pl1, surfCenter, outCircleRadius - offSetStone); Circle circleDist = new Circle(pl1, surfCenter, outCircleRadius + stoneDist); Guid cir_guid = doc.Objects.AddCircle(circle); cir_guid_list.Add(cir_guid); //Cut tween curve at latest circle center Point3d pointOnCurve; Point3d pointOnCircle; Curve circleDistCurve = circleDist.ToNurbsCurve(); tCurve.Domain = new Interval(0, tCurve.GetLength()); Curve[] splitCurves = tCurve.Split(outCircleRadius); if (splitCurves is null) { break; } tCurve = splitCurves[splitCurves.Length - 1]; tCurve.ClosestPoints(circleDistCurve, out pointOnCurve, out pointOnCircle); //Cut tween curve at latest circle border double curveSplitParam; tCurve.Domain = new Interval(0, tCurve.GetLength()); tCurve.ClosestPoint(pointOnCurve, out curveSplitParam); splitCurves = tCurve.Split(curveSplitParam); if (splitCurves is null) { break; } tCurve = splitCurves[splitCurves.Length - 1]; //New parameter at curve1 double circleParam; circleDistCurve.ClosestPoint(pointOnCircle, out circleParam); param1 = circleParam; curve1 = circleDistCurve; //New parameter at curves[0] double paramCurve0New; curve2.ClosestPoint(pointOnCircle, out paramCurve0New); Point3d pointCurve0New = curve2.PointAt(paramCurve0New); double distNewPoints0 = pointOnCircle.DistanceTo(pointCurve0New); param2 = paramCurve0New + distNewPoints0; //New parameter at curves[1] double paramCurve1New; curve3.ClosestPoint(pointOnCircle, out paramCurve1New); Point3d pointCurve1New = curve3.PointAt(paramCurve1New); double distNewPoints1 = pointOnCircle.DistanceTo(pointCurve1New); param3 = paramCurve1New + distNewPoints1; } doc.Views.Redraw(); //Options var go = new GetOption(); go.SetCommandPrompt("Set options."); var stoneOff = new Rhino.Input.Custom.OptionDouble(offSetStone); var distStone = new Rhino.Input.Custom.OptionDouble(stoneDist); var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On"); go.AddOptionDouble("Offset", ref stoneOff); go.AddOptionDouble("Distance", ref distStone); go.AddOptionToggle("Reverse", ref boolOption); go.AcceptNothing(true); var res = go.Get(); if (res == GetResult.Nothing) { break; } if (res == GetResult.Cancel) { break; } foreach (var gui in cir_guid_list) { var gu = doc.Objects.Find(gui); doc.Objects.Delete(gu); } offSetStone = stoneOff.CurrentValue; stoneDist = distStone.CurrentValue; optionBool = boolOption.CurrentValue; if (optionBool == true) { curve2.Reverse(); curve2 = curve2.Rebuild(60, 3, false); curve3.Reverse(); curve3 = curve3.Rebuild(60, 3, false); optionBool = false; } } } else { while (true) { cir_guid_list = new List <Guid>(); List <Point3d> points = new List <Point3d>(); double length = (diamStone / 2) + offSetStone; double crv_length = curve.GetLength(); Point3d point = curve.PointAtLength(length); points.Add(point); while (true) { length += diamStone + offSetStone; if (length > crv_length) { break; } point = curve.PointAtLength(length); points.Add(point); } foreach (var poi in points) { double u, v; surface.ClosestPoint(poi, out u, out v); var direction = surface.NormalAt(u, v); double x = direction.X; double y = direction.Y; double z = direction.Z; Vector3d vt1 = new Vector3d(x, y, z); Plane pl1 = new Plane(poi, vt1); Circle circle = new Circle(pl1, poi, diamStone / 2); Guid cir_guid = doc.Objects.AddCircle(circle); cir_guid_list.Add(cir_guid); } doc.Views.Redraw(); //Options var go = new GetOption(); go.SetCommandPrompt("Set options."); var stoneDiam = new Rhino.Input.Custom.OptionDouble(diamStone); var stoneOff = new Rhino.Input.Custom.OptionDouble(offSetStone); var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On"); go.AddOptionDouble("StoneDiam", ref stoneDiam); go.AddOptionDouble("Offset", ref stoneOff); go.AddOptionToggle("Reverse", ref boolOption); go.AcceptNothing(true); var res = go.Get(); if (res == GetResult.Nothing) { break; } if (res == GetResult.Cancel) { break; } foreach (var gui in cir_guid_list) { var gu = doc.Objects.Find(gui); doc.Objects.Delete(gu); } diamStone = stoneDiam.CurrentValue; offSetStone = stoneOff.CurrentValue; optionBool = boolOption.CurrentValue; if (optionBool == true) { curve.Reverse(); } } } doc.Views.Redraw(); doc.Groups.Add(cir_guid_list); 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 void curves(int state, Rhino.DocObjects.RhinoObject geo) { //Verify geometery is being added, not transformed. string G00_Path = utils.file_structure.getPathFor("G00"); int verifyState = Convert.ToInt32(System.IO.File.ReadAllText(G00_Path)); if (verifyState == 3) { state = 3; } else { System.IO.File.WriteAllText(G00_Path, state.ToString()); } //Grab reference point from docBox. Rhino.Geometry.Point3d refPoint = utils.properties.getRefPoint(); double refPointX = refPoint.X; double refPointY = refPoint.Y; //Determine and sanitize cache file for new geometry. string G10_Path = utils.file_structure.getPathFor("G10"); if (System.IO.File.Exists(G10_Path) == false) { System.IO.File.WriteAllText(G10_Path, ""); //System.Threading.Thread.Sleep(500); } //Parse curve geometry from RhinoObject. Guid incomingGuid = geo.Id; Rhino.Geometry.Curve newCurve = null; int layerIndex = geo.Attributes.LayerIndex; Rhino.DocObjects.Layer incomingLayer = Rhino.RhinoDoc.ActiveDoc.Layers[layerIndex]; string incomingLayerName = incomingLayer.Name; Rhino.DocObjects.ObjRef oRef = new Rhino.DocObjects.ObjRef(incomingGuid); //Verify object is a curve, otherwise quit. if (oRef.Geometry().ObjectType.ToString().ToLower().Contains("curve")) { newCurve = oRef.Curve(); } else { //System.IO.File.AppendAllText(G10_Path, "X|" + Environment.NewLine); return; } //Run curve geometry through the coin sorter. //All data is cached in the same file, but keyed at the beginning by type. //0 - linear curve //1 - linear polyline //2 - arc //3 - circle //4 - ellipse //5 - arbitrary curve //6 - complex polycurve //New type key: //0 - linear curve //1 - linear polyline //2 - any non-linear curve if (newCurve.Degree == 1) { if (newCurve.SpanCount == 1) { //Treat as linear curve. //utils.debug.ping(0, "Linear curve added!"); Rhino.Geometry.Point3d startPoint = newCurve.PointAtStart; Rhino.Geometry.Point3d endPoint = newCurve.PointAtEnd; string x1 = (startPoint.X - refPointX).ToString(); string y1 = (startPoint.Y - refPointY).ToString(); string x2 = (endPoint.X - refPointX).ToString(); string y2 = (endPoint.Y - refPointY).ToString(); //utils.debug.alert(G10_Path); //utils.debug.alert(incomingGuid.ToString()); //utils.debug.alert(incomingLayerName); try { System.IO.File.AppendAllText(G10_Path, "0|" + incomingGuid.ToString() + "|" + incomingLayerName + "|1|" + x1 + "," + y1 + "," + x2 + "," + y2 + Environment.NewLine); } catch (Exception e) { utils.debug.alert(e.ToString()); } //utils.debug.alert("Pausing!!"); } else if (newCurve.SpanCount > 1) { //Treat as linear polyline. //utils.debug.ping(0, "Linear polyline added!"); List <string> coords = new List <string>(); int spanCount = newCurve.SpanCount; for (int i = 0; i < spanCount; i++) { double activeParameter = newCurve.SpanDomain(i).Min; Rhino.Geometry.Point3d activePoint = newCurve.PointAt(activeParameter); double activeX = activePoint.X - refPointX; coords.Add(activeX.ToString()); double activeY = activePoint.Y - refPointY; coords.Add(activeY.ToString()); if (i == spanCount - 1) { //On reaching final span, also record endpoint. double finalParameter = newCurve.SpanDomain(i).Max; Rhino.Geometry.Point3d finalPoint = newCurve.PointAt(finalParameter); double finalX = finalPoint.X - refPointX; coords.Add(finalX.ToString()); double finalY = finalPoint.Y - refPointY; coords.Add(finalY.ToString()); } } string coordInfo = string.Join(",", coords); System.IO.File.AppendAllText(G10_Path, "1|" + incomingGuid.ToString() + "|" + incomingLayerName + "|" + newCurve.SpanCount.ToString() + "|" + coordInfo + Environment.NewLine); } } else if (newCurve.Degree > 1) { //Generate degree 3 approximation of incoming curve. (Low tolerance makes it more than "good enough") Rhino.Geometry.BezierCurve[] bCurveSpans = Rhino.Geometry.BezierCurve.CreateCubicBeziers(newCurve, 0.01, 0.01); int bCurveCount = bCurveSpans.Length; List <string> bPointData = new List <string>(); List <double> bPointCache = new List <double>(); //Cache point info. for (int i = 0; i < bCurveCount; i++) { //Starting point caching process. if (i == 0) { //Parse anchor point data. Rhino.Geometry.Point3d activeAnchor = bCurveSpans[i].GetControlVertex3d(0); double activeAnchorX = activeAnchor.X - refPointX; double activeAnchorY = activeAnchor.Y - refPointY; bPointCache.Add(activeAnchorX); bPointCache.Add(activeAnchorY); //Parse left direction data. For starting point, this is the same as the anchor. bPointCache.Add(activeAnchorX); bPointCache.Add(activeAnchorY); //Parse right direction data. Rhino.Geometry.Point3d activeRightDirection = bCurveSpans[i].GetControlVertex3d(1); double activeRightDirectionX = activeRightDirection.X - refPointX; double activeRightDirectionY = activeRightDirection.Y - refPointY; bPointCache.Add(activeRightDirectionX); bPointCache.Add(activeRightDirectionY); //Push packaged point data to final list. string bPoint = string.Join(":", bPointCache); bPointData.Add(bPoint); bPointCache.Clear(); } //Intermediate point caching process. else { //Parse anchor point data. Rhino.Geometry.Point3d activeAnchor = bCurveSpans[i].GetControlVertex3d(0); double activeAnchorX = activeAnchor.X - refPointX; double activeAnchorY = activeAnchor.Y - refPointY; bPointCache.Add(activeAnchorX); bPointCache.Add(activeAnchorY); //Parse left direction data. Rhino.Geometry.Point3d activeLeftDirection = bCurveSpans[i - 1].GetControlVertex3d(2); double activeLeftDirectionX = activeLeftDirection.X - refPointX; double activeLeftDirectionY = activeLeftDirection.Y - refPointY; bPointCache.Add(activeLeftDirectionX); bPointCache.Add(activeLeftDirectionY); //Parse right direction data. Rhino.Geometry.Point3d activeRightDirection = bCurveSpans[i].GetControlVertex3d(1); double activeRightDirectionX = activeRightDirection.X - refPointX; double activeRightDirectionY = activeRightDirection.Y - refPointY; bPointCache.Add(activeRightDirectionX); bPointCache.Add(activeRightDirectionY); //Push packaged point data to final list. string bPoint = string.Join(":", bPointCache); bPointData.Add(bPoint); bPointCache.Clear(); } } //Cache endpoint info after loop finishes. //Parse anchor point data. Rhino.Geometry.Point3d lastActiveAnchor = bCurveSpans[bCurveCount - 1].GetControlVertex3d(3); double lastActiveAnchorX = lastActiveAnchor.X - refPointX; double lastActiveAnchorY = lastActiveAnchor.Y - refPointY; bPointCache.Add(lastActiveAnchorX); bPointCache.Add(lastActiveAnchorY); //Parse left direction data. Rhino.Geometry.Point3d lastActiveLeftDirection = bCurveSpans[bCurveCount - 1].GetControlVertex3d(2); double lastActiveLeftDirectionX = lastActiveLeftDirection.X - refPointX; double lastActiveLeftDirectionY = lastActiveLeftDirection.Y - refPointY; bPointCache.Add(lastActiveLeftDirectionX); bPointCache.Add(lastActiveLeftDirectionY); //Parse right direction data. For the ending point, this is the same as the anchor. bPointCache.Add(lastActiveAnchorX); bPointCache.Add(lastActiveAnchorY); //Push packaged point data to final list. string lastBPoint = string.Join(":", bPointCache); bPointData.Add(lastBPoint); bPointCache.Clear(); //Finalize and record data. string coordInfo = string.Join(";", bPointData); System.IO.File.AppendAllText(G10_Path, "2|" + incomingGuid.ToString() + "|" + incomingLayerName + "|" + newCurve.SpanCount.ToString() + "|" + coordInfo + Environment.NewLine); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { String[] matName = new String[] { "WhiteGold_18ct", "YellowGold_18ct", "RedGold_18ct", "RodiumBlack_18ct", "Silver_925", "Platinum_960", "Ruby", "Emerald", "Saphir", "Paraiba", "Granat", "Amethyst", "Morganite", "Diamond" }; Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings(); settings.VisibleFilter = true; System.Collections.Generic.List <Guid> ids = new System.Collections.Generic.List <Guid>(); List <string> allItems = new List <string>(); List <string> metalItems = new List <string>(); List <string> stoneItems = new List <string>(); List <double> circleStones = new List <double>(); List <int> quantCirclesStones = new List <int>(); foreach (Rhino.DocObjects.RhinoObject rhObj in doc.Objects.GetObjectList(settings)) { var objType = rhObj.ObjectType; Guid objGuid = rhObj.Id; Rhino.DocObjects.ObjRef objref = new Rhino.DocObjects.ObjRef(objGuid); if (objType == Rhino.DocObjects.ObjectType.Curve) { Curve curveRadius = objref.Curve(); Circle circleRadius = new Circle(); var circlefound = curveRadius.TryGetCircle(out circleRadius, doc.ModelAbsoluteTolerance); if (circlefound) { double diamStone = Math.Round(circleRadius.Diameter, 2, MidpointRounding.AwayFromZero); int match = circleStones.IndexOf(diamStone); if (match == -1) { circleStones.Add(diamStone); quantCirclesStones.Add(1); } else { int currVal = quantCirclesStones[match]; quantCirclesStones[match] = currVal + 1; } } } Rhino.DocObjects.Material mat = rhObj.GetMaterial(true); var objMatName = mat.Name; int pos = Array.IndexOf(matName, objMatName); if (pos == -1) { continue; } switch (pos) { //18ctGold case int n when(n < 4): double gold18ct = 0.016; CalMat(doc, gold18ct, objType, objref, metalItems, matName, pos, " g"); break; //Silver case 4: double silver = 0.0105; CalMat(doc, silver, objType, objref, metalItems, matName, pos, " g"); break; //Platinum case 5: double platinum = 0.0203; CalMat(doc, platinum, objType, objref, metalItems, matName, pos, " g"); break; //ColorStones ruby=4g Emerald=2.65g saphr=4g Paraiba=3g Granat=3.9g Amethyst=2.65 Morganite=2.65 case 6: double ruby = 0.02; CalMat(doc, ruby, objType, objref, stoneItems, matName, pos, " ct"); break; case 7: double emerald = 0.0133; CalMat(doc, emerald, objType, objref, stoneItems, matName, pos, " ct"); break; case 8: double saphir = 0.02; CalMat(doc, saphir, objType, objref, stoneItems, matName, pos, " ct"); break; case 9: double paraiba = 0.015; CalMat(doc, paraiba, objType, objref, stoneItems, matName, pos, " ct"); break; case 10: double granat = 0.0195; CalMat(doc, granat, objType, objref, stoneItems, matName, pos, " ct"); break; case 11: double amethyst = 0.0133; CalMat(doc, amethyst, objType, objref, stoneItems, matName, pos, " ct"); break; case 12: double morganite = 0.0133; CalMat(doc, morganite, objType, objref, stoneItems, matName, pos, " ct"); break; //Diamond case 13: double diamond = 0.02; CalMat(doc, diamond, objType, objref, stoneItems, matName, pos, " ct"); break; } } metalItems.Sort(); stoneItems.Sort(); allItems.Add("------Metals(g)/Stones(ct) from solids-------"); for (int i = 0; i < materials.Length; i++) { if (materials[i] == 0) { continue; } allItems.Add(matName[i] + ": " + materials[i]); } /* * allItems.Add("--------------Metals--------------"); * for (int i = 0; i < metalItems.Count; i++) * { * allItems.Add(metalItems[i]); * } * * allItems.Add("--------------Stone---------------"); * for (int i = 0; i < stoneItems.Count; i++) * { * allItems.Add(stoneItems[i]); * } */ allItems.Add("-----------------------------------------------"); allItems.Add(""); allItems.Add("-----------Brillants from circles------------"); double totalCt = 0.0; for (int i = 0; i < circleStones.Count; i++) { double ct; ct = Math.Round((circleStones[i] * circleStones[i] * circleStones[i] * 0.6 * 0.0061), 4, MidpointRounding.AwayFromZero); allItems.Add("Brill: " + quantCirclesStones[i] + " x " + circleStones[i] + " mm " + ct + " ct Total: " + ct * quantCirclesStones[i] + " ct"); totalCt = totalCt + ct * quantCirclesStones[i]; } allItems.Add("Total brillant weight: " + totalCt + " ct"); allItems.Add("-----------------------------------------------"); String clipboardString = ""; foreach (String o in allItems) { clipboardString = clipboardString + o + "\n"; } Clipboard.SetText(clipboardString); if (open > 0) { Dialogs.ShowMessage("At least one object is not closed. Weights might be false.", "Warning!"); } Dialogs.ShowListBox("Report", "This data is copied to your clipboard \n Use Ctrl+V to paste", allItems); materials = new double[14]; open = 0; return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Mesh meshSurf; List <Guid> ids = new List <Guid>(); double tolerance = doc.ModelAbsoluteTolerance; const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; GetObject gs = new Rhino.Input.Custom.GetObject(); gs.SetCommandPrompt("Surface to orient on"); gs.GeometryFilter = geometryFilter; gs.SubObjectSelect = true; gs.DeselectAllBeforePostSelect = true; gs.OneByOnePostSelect = true; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } Rhino.DocObjects.ObjRef objref = gs.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } brepSurf = objref.Brep(); if (brepSurf == null) { meshSurf = objref.Mesh(); brepSurf = Brep.CreateFromMesh(meshSurf, true); } if (brepSurf == null) { return(Result.Failure); } obj.Select(false); while (true) { w_key_pressed = false; s_key_pressed = false; a_key_pressed = false; d_key_pressed = false; m_escape_key_pressed = false; RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed; RhinoApp.KeyboardEvent += OnRhinoKeyboardEvent; Point3d pt0; GetPoint getPointAction = new GetPoint(); getPointAction.SetCommandPrompt("Please select insert point(s) on surface."); getPointAction.Constrain(brepSurf, -1, -1, false); var stoneDiam = new Rhino.Input.Custom.OptionDouble(diamStone); var stoneOff = new Rhino.Input.Custom.OptionDouble(offSetStone); var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On"); var moveOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On"); getPointAction.AddOptionDouble("StoneDiam", ref stoneDiam); getPointAction.AddOptionDouble("Offset", ref stoneOff); getPointAction.AddOptionToggle("Delete", ref boolOption); getPointAction.AddOptionToggle("Move", ref moveOption); getPointAction.DynamicDraw += RefCircleDraw; getPointAction.Tag = obj; getPointAction.AcceptString(false); getPointAction.AcceptNothing(true); var res = getPointAction.Get(); if (w_key_pressed || s_key_pressed) { RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent; w_key_pressed = false; s_key_pressed = false; stoneDiam.CurrentValue = diamStone; } if (a_key_pressed || d_key_pressed) { RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent; a_key_pressed = false; d_key_pressed = false; stoneOff.CurrentValue = offSetStone; } if (res == GetResult.Nothing) { break; } if (m_escape_key_pressed) { break; } diamStone = stoneDiam.CurrentValue; offSetStone = stoneOff.CurrentValue; optionBool = boolOption.CurrentValue; moveBool = moveOption.CurrentValue; RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent; if (moveBool == true) { RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent; while (true) { GetObject gcd = new Rhino.Input.Custom.GetObject(); gcd.SetCommandPrompt("Select circle(s) to move. Press enter when done"); gcd.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gcd.SubObjectSelect = false; gcd.DeselectAllBeforePostSelect = true; gcd.AcceptNothing(true); if (gcd.Get() == GetResult.Nothing) { break; } gcd.Get(); Rhino.DocObjects.ObjRef delobjref = gcd.Object(0); Rhino.DocObjects.RhinoObject delobj = delobjref.Object(); Curve curveRadius = delobjref.Curve(); Circle circleRadius = new Circle(); curveRadius.TryGetCircle(out circleRadius, tolerance); diamStone = circleRadius.Diameter; doc.Objects.Delete(delobj, true); doc.Views.Redraw(); getPointAction.Get(); pt0 = getPointAction.Point(); Point3d closestPoint; ComponentIndex compIndex; double u, v; Vector3d vt1; brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1); Plane pl1 = new Plane(pt0, vt1); Circle cr1 = new Circle(pl1, pt0, diamStone / 2); var crgu = doc.Objects.AddCircle(cr1); ids.Add(crgu); doc.Views.Redraw(); } moveBool = false; } if (optionBool == true) { RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent; while (true) { GetObject gcd = new Rhino.Input.Custom.GetObject(); gcd.SetCommandPrompt("Select circle(s) to delete. Press enter when done"); gcd.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gcd.SubObjectSelect = false; gcd.DeselectAllBeforePostSelect = true; gcd.AcceptNothing(true); if (gcd.Get() == GetResult.Nothing) { break; } gcd.Get(); Rhino.DocObjects.ObjRef delobjref = gcd.Object(0); Rhino.DocObjects.RhinoObject delobj = delobjref.Object(); Curve curveRadius = delobjref.Curve(); Circle circleRadius = new Circle(); curveRadius.TryGetCircle(out circleRadius, tolerance); diamStone = circleRadius.Diameter; doc.Objects.Delete(delobj, true); doc.Views.Redraw(); } optionBool = false; } if (res == GetResult.Point) { pt0 = getPointAction.Point(); Point3d closestPoint; ComponentIndex compIndex; double u, v; Vector3d vt1; brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1); Plane pl1 = new Plane(pt0, vt1); Circle cr1 = new Circle(pl1, pt0, diamStone / 2); var crgu = doc.Objects.AddCircle(cr1); ids.Add(crgu); doc.Views.Redraw(); } } RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent; 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) { //Pick curve for chain GetObject getCurve = new GetObject(); getCurve.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; getCurve.SetCommandPrompt("Select curve for chain"); var res = getCurve.Get(); Rhino.DocObjects.ObjRef objref = getCurve.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } curve = objref.Curve(); if (curve == null) { return(Result.Failure); } obj.Select(false); //Pick object for chain (instance) //pick objekt to orient GetObject go = new GetObject(); go.SetCommandPrompt("Select chain element."); go.SubObjectSelect = true; go.DeselectAllBeforePostSelect = false; //go.GroupSelect = true; //go.GetMultiple(1, -1); go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } Rhino.DocObjects.ObjRef objref1 = go.Object(0); Rhino.DocObjects.RhinoObject obj1 = objref1.Object(); GeometryBase obj1Base = obj1.Geometry; int obCount = go.ObjectCount; string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); //create block instance and plane for instance Rhino.Input.Custom.GetPoint gp1 = new Rhino.Input.Custom.GetPoint(); gp1.SetCommandPrompt("Center point to orient from"); gp1.Get(); if (gp1.CommandResult() != Rhino.Commands.Result.Success) { return(gp1.CommandResult()); } Point3d pt1 = gp1.Point(); Rhino.Input.Custom.GetPoint gp2 = new Rhino.Input.Custom.GetPoint(); gp2.SetCommandPrompt("Point for orientation"); gp2.DrawLineFromPoint(pt1, false); gp2.Get(); if (gp2.CommandResult() != Rhino.Commands.Result.Success) { return(gp2.CommandResult()); } Point3d pt2 = gp2.Point(); Vector3d vt1 = pt2 - pt1; sourcePlane = new Plane(pt1, vt1); Plane originPlane = new Plane(Point3d.Origin, vt1); Transform bform = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane); obj1Base.Transform(bform); GeometryBase[] obj1List = new GeometryBase[1] { obj1Base }; var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List); //orient instances along curve List <Guid> chainBlocks = new List <Guid>(); Guid chainBlock; while (true) { foreach (var block in chainBlocks) { doc.Objects.Delete(block, false); } chainBlocks = new List <Guid>(); double curveLength = curve.GetLength(); double curveDivide = curveLength / chainDis; int curveDivideInt = Convert.ToInt32(curveDivide); for (int ic = 0; ic < curveDivideInt; ic++) { Point3d insertPoint = curve.PointAtLength(chainDis * ic); Vector3d insertVec = curve.PointAtLength(chainDis * ic + 1) - curve.PointAtLength(chainDis * ic - 1); Plane targetPlane = new Plane(insertPoint, insertVec); var xvec = targetPlane.XAxis; if (xvec.Z != 0) { targetPlane.Rotate(Math.PI / 2, insertVec); } var yvec = targetPlane.YAxis; if (yvec.Z < 0) { targetPlane.Rotate(Math.PI, insertVec); } if (ic % 2 == 0) { targetPlane.Rotate(Math.PI / 2, insertVec); } targetPlane.Rotate(axisOffsetRadiant, insertVec); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, targetPlane); chainBlock = doc.Objects.AddInstanceObject(orientBlock, xform); chainBlocks.Add(chainBlock); } doc.Views.Redraw(); GetOption gd = new GetOption(); gd.SetCommandPrompt("Set distance between element centers in mm and rotation offset in degree. Press enter to accept."); var dis = new Rhino.Input.Custom.OptionDouble(chainDis); var axisOffset = new Rhino.Input.Custom.OptionInteger(chainAxisOffset); gd.AddOptionDouble("distance", ref dis); gd.AddOptionInteger("rotation", ref axisOffset); gd.AcceptNothing(true); var resdis = gd.Get(); if (resdis == GetResult.Nothing) { break; } chainDis = dis.CurrentValue; chainAxisOffset = axisOffset.CurrentValue; axisOffsetRadiant = chainAxisOffset * (Math.PI / 180); } int index = doc.Groups.Add(chainBlocks); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var layerCheck = doc.Layers.FindName("CurveToCircle"); if (layerCheck == null) { doc.Layers.Add("CurveToCircle", System.Drawing.Color.Turquoise); layerCheck = doc.Layers.FindName("CurveToCircle"); } GetObject gc = new GetObject(); gc.SetCommandPrompt("Select curves to make into circles"); gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gc.GroupSelect = true; gc.SubObjectSelect = false; gc.EnableClearObjectsOnEntry(false); gc.EnableUnselectObjectsOnExit(false); gc.DeselectAllBeforePostSelect = false; gc.GetMultiple(1, 0); for (int i = 0; i < gc.ObjectCount; i++) { Rhino.DocObjects.ObjRef objref = gc.Object(i); var curve = objref.Curve(); if (curve == null) { return(Result.Nothing); } Circle circle; if (!curve.TryGetCircle(out circle)) { if (!curve.IsClosed) { if (curve.IsClosable(doc.ModelAbsoluteTolerance)) { curve.MakeClosed(doc.ModelAbsoluteTolerance); } else { Curve blendCurve; blendCurve = Curve.CreateBlendCurve(curve, curve, BlendContinuity.Curvature); Curve[] curveSet = { curve, blendCurve }; Curve[] joinedCurve = Curve.JoinCurves(curveSet); curve = joinedCurve[0]; } } //curve.Rebuild(3,2,true); double[] curveDivide = curve.DivideByCount(8, true); Point3d curvePoint; Point3d[] curvePoints = new Point3d[8]; for (int d = 0; d < 8; d++) { curvePoint = curve.PointAt(curveDivide[d]); curvePoints[d] = curvePoint; } if (!Circle.TryFitCircleToPoints(curvePoints, out circle)) { circle = new Circle(5); } } var circGuid = doc.Objects.AddCircle(circle); Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(circGuid); circObj.Attributes.LayerIndex = layerCheck.Index; circObj.CommitChanges(); } doc.Views.Redraw(); 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 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); }