protected override Result RunCommand(RhinoDoc doc, RunMode mode) { double length = 10; var result = RhinoGet.GetNumber("Select length", false, ref length); if (result != Result.Success) { return(result); } var objects = doc.Objects.FindByObjectType(ObjectType.Curve); doc.Objects.Delete(_baked, true); _baked.Clear(); foreach (var obj in objects) { var curve = obj.Geometry as Curve; var extrusion = Surface.CreateExtrusion(curve, Vector3d.ZAxis * length); var guid = doc.Objects.AddSurface(extrusion); _baked.Add(guid); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // get plane var rc = RhinoGet.GetPlane(out var plane); if (rc != Result.Success) { return(rc); } // get radius double radius = 0; rc = RhinoGet.GetNumber("Specify Radius", false, ref radius, 0.1, 1000000); if (rc != Result.Success) { return(rc); } // create spheredata var data = new SphereData(plane, radius); // and sphere object var sphereObject = data.CreateCustomObject(); // add sphereObject to doc doc.Objects.AddRhinoObject(sphereObject); //redraw views doc.Views.Redraw(); // return success return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { #region user input // select a surface var gs = new GetObject(); gs.SetCommandPrompt("select surface"); gs.GeometryFilter = ObjectType.Surface; gs.DisablePreSelect(); gs.SubObjectSelect = false; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } // get the brep var brep = gs.Object(0).Brep(); if (brep == null) { return(Result.Failure); } // get X and Y double x = 0.0, y = 0.0; var rc = RhinoGet.GetNumber("value of X coordinate", true, ref x); if (rc != Result.Success) { return(rc); } rc = RhinoGet.GetNumber("value of Y coordinate", true, ref y); if (rc != Result.Success) { return(rc); } #endregion // an earlier version of this sample used a curve-brep intersection to find Z //var maxZ = maxZIntersectionMethod(brep, x, y, doc.ModelAbsoluteTolerance); // projecting points is another way to find Z var max_z = MaxZProjectionMethod(brep, x, y, doc.ModelAbsoluteTolerance); if (max_z != null) { RhinoApp.WriteLine("Maximum surface Z coordinate at X={0}, Y={1} is {2}", x, y, max_z); doc.Objects.AddPoint(new Point3d(x, y, max_z.Value)); doc.Views.Redraw(); } else { RhinoApp.WriteLine("no maximum surface Z coordinate at X={0}, Y={1} found.", x, y); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //GET DATA FROM THE USER //Select multiple points ObjRef[] obj_refs; List <Point3d> finalPts = new List <Point3d>(); var rc = RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs); if (rc != Result.Success) { return(rc); } foreach (var o_ref in obj_refs) { var point = o_ref.Point(); finalPts.Add(point.Location); } doc.Objects.UnselectAll(); int depth = 0; var rc1 = RhinoGet.GetInteger("The Depth of the Snowflake?", false, ref depth, 0, 5); if (rc1 != Result.Success) { return(rc1); } double radius = 10; var rc2 = RhinoGet.GetNumber("The size of the Snowflake?", false, ref radius); if (rc2 != Result.Success) { return(rc2); } //CREATE SNOWFLAKES FOR EACH SELECTED POINT AND DEPTH AND RADIUS foreach (Point3d pt in finalPts) { //STEP 1 - Create the initial triangle (just a list of 3 points) List <Point3d> triangle = GenerateSnowflakeTriangle(pt, radius); //STEP 2 - FROM TRIANGLE TO SNOWFLAKE List <Point3d> snowflake = GenerateSnowflake(triangle, depth, doc); } return(Result.Success); }
public static Result ReparameterizeCurve(RhinoDoc doc) { ObjRef obj_ref; var rc = RhinoGet.GetOneObject("Select curve to reparameterize", false, ObjectType.Curve, out obj_ref); if (rc != Result.Success) { return(rc); } var curve = obj_ref.Curve(); if (curve == null) { return(Result.Failure); } double domain_start = 0; rc = RhinoGet.GetNumber("Domain start", false, ref domain_start); if (rc != Result.Success) { return(rc); } double domain_end = 0; rc = RhinoGet.GetNumber("Domain end", false, ref domain_end); if (rc != Result.Success) { return(rc); } if (Math.Abs(curve.Domain.T0 - domain_start) < RhinoMath.ZeroTolerance && Math.Abs(curve.Domain.T1 - domain_end) < RhinoMath.ZeroTolerance) { return(Result.Nothing); } var curve_copy = curve.DuplicateCurve(); curve_copy.Domain = new Interval(domain_start, domain_end); if (!doc.Objects.Replace(obj_ref, curve_copy)) { return(Result.Failure); } else { doc.Views.Redraw(); return(Result.Success); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // get plane var rc = RhinoGet.GetPlane(out var plane); if (rc != Result.Success) { return(rc); } // get length double length = 0; rc = RhinoGet.GetNumber("Specify length", false, ref length, 0.1, 1000000); if (rc != Result.Success) { return(rc); } // get width double width = 0; rc = RhinoGet.GetNumber("Specify width", false, ref width, 0.1, 1000000); if (rc != Result.Success) { return(rc); } // get height double height = 0; rc = RhinoGet.GetNumber("Specify height", false, ref height, 0.1, 1000000); if (rc != Result.Success) { return(rc); } // create rectangleData var data = new BoxData(plane, length, width, height); // and sphere object var boxObject = data.CreateCustomObject(); // add sphereObject to doc doc.Objects.AddRhinoObject(boxObject); //redraw views doc.Views.Redraw(); // return success return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { double psize = doc.Views.ActiveView.DisplayPipeline.DisplayPipelineAttributes.PointRadius; Result res = RhinoGet.GetNumber("Set point size", true, ref psize, 0.1, 10); //if (res != Result.Success) //{ // return res; //} RhinoApp.WriteLine(string.Format("New point size: {0}", psize)); doc.Views.ActiveView.DisplayPipeline.DisplayPipelineAttributes.PointRadius = (float)psize; doc.Views.ActiveView.ActiveViewport.DisplayMode.DisplayAttributes.PointRadius = (float)psize; RFContext.PointSize = psize; return(Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { var apartmentHousesPercetage = new double(); var population = new double(); ObjRef[] srcCurves; RhinoGet.GetMultipleObjects("ClosedPolygones", false, ObjectType.Curve, out srcCurves); RhinoGet.GetNumber("Insert population", false, ref population, 0, 1000000); RhinoGet.GetNumber("Percent of population living in apartment houses", false, ref apartmentHousesPercetage, 0, 100000); var dicts = new Dictionary <Guid, DataDto>(); for (var i = 0; i < srcCurves.Count(); i++) { var o = GetDto(srcCurves[i]); dicts.Add(srcCurves[i].ObjectId, o); } var optimalLivingArea = GetOptimalLivingArea((int)Math.Round(population), (int)Math.Round(apartmentHousesPercetage)); var excistingLivingArea = GetExcistingLivingArea(dicts); if (optimalLivingArea > 0 && excistingLivingArea > 0) { var overStockPercent = (excistingLivingArea - optimalLivingArea) * 100 / excistingLivingArea; RhinoApp.WriteLine($"Overstock {overStockPercent} percent"); } else { RhinoApp.WriteLine($"No info to calculate overstock percent"); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gc1 = new GetObject(); gc1.DisablePreSelect(); gc1.SetCommandPrompt("Select first curve to fillet (close to the end you want to fillet)"); gc1.GeometryFilter = ObjectType.Curve; gc1.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve; gc1.Get(); if (gc1.CommandResult() != Result.Success) { return(gc1.CommandResult()); } var curve1_obj_ref = gc1.Object(0); var curve1 = curve1_obj_ref.Curve(); if (curve1 == null) { return(Result.Failure); } var curve1_point_near_end = curve1_obj_ref.SelectionPoint(); if (curve1_point_near_end == Point3d.Unset) { return(Result.Failure); } var gc2 = new GetObject(); gc2.DisablePreSelect(); gc2.SetCommandPrompt("Select second curve to fillet (close to the end you want to fillet)"); gc2.GeometryFilter = ObjectType.Curve; gc2.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve; gc2.Get(); if (gc2.CommandResult() != Result.Success) { return(gc2.CommandResult()); } var curve2_obj_ref = gc2.Object(0); var curve2 = curve2_obj_ref.Curve(); if (curve2 == null) { return(Result.Failure); } var curve2_point_near_end = curve2_obj_ref.SelectionPoint(); if (curve2_point_near_end == Point3d.Unset) { return(Result.Failure); } double radius = 0; var rc = RhinoGet.GetNumber("fillet radius", false, ref radius); if (rc != Result.Success) { return(rc); } var join = false; var trim = true; var arc_extension = true; var fillet_curves = Curve.CreateFilletCurves(curve1, curve1_point_near_end, curve2, curve2_point_near_end, radius, join, trim, arc_extension, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceDegrees); if (fillet_curves == null /*|| fillet_curves.Length != 3*/) { return(Result.Failure); } foreach (var fillet_curve in fillet_curves) { doc.Objects.AddCurve(fillet_curve); } doc.Views.Redraw(); return(rc); }
public static Result DivideCurveStraight(RhinoDoc doc) { // user input ObjRef[] obj_refs; var rc = RhinoGet.GetMultipleObjects("Select curve to divide", false, ObjectType.Curve | ObjectType.EdgeFilter, out obj_refs); if (rc != Result.Success || obj_refs == null) { return(rc); } double distance_between_divisions = 5; rc = RhinoGet.GetNumber("Distance between divisions", false, ref distance_between_divisions, 1.0, Double.MaxValue); if (rc != Result.Success) { return(rc); } // generate the points var points = new List <Point3d>(); foreach (var obj_ref in obj_refs) { var curve = obj_ref.Curve(); if (curve == null) { return(Result.Failure); } var t0 = curve.Domain.Min; points.Add(curve.PointAt(t0)); var sphere_center = curve.PointAt(t0); var t = t0; var rest_of_curve = curve; while (true) { var sphere = new Sphere(sphere_center, distance_between_divisions); Curve[] overlap_curves; Point3d[] intersect_points; var b = Intersection.CurveBrep(rest_of_curve, sphere.ToBrep(), 0.0, out overlap_curves, out intersect_points); if (!b || (overlap_curves.Length == 0 && intersect_points.Length == 0)) { break; } double intersect_param; Point3d intersect_point; NextintersectParamAndPoint(overlap_curves, intersect_points, rest_of_curve, out intersect_param, out intersect_point); points.Add(intersect_point); t = intersect_param; sphere_center = intersect_point; rest_of_curve = curve.Split(t)[1]; } } foreach (var point in points) { doc.Objects.AddPoint(point); } doc.Views.Redraw(); return(Result.Success); }
public static Result ContourCurves(RhinoDoc doc) { var filter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh; ObjRef[] obj_refs; var rc = RhinoGet.GetMultipleObjects("Select objects to contour", false, filter, out obj_refs); if (rc != Result.Success) { return(rc); } var gp = new GetPoint(); gp.SetCommandPrompt("Contour plane base point"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var base_point = gp.Point(); gp.DrawLineFromPoint(base_point, true); gp.SetCommandPrompt("Direction perpendicular to contour planes"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var end_point = gp.Point(); if (base_point.DistanceTo(end_point) < RhinoMath.ZeroTolerance) { return(Result.Nothing); } double distance = 1.0; rc = RhinoGet.GetNumber("Distance between contours", false, ref distance); if (rc != Result.Success) { return(rc); } var interval = Math.Abs(distance); Curve[] curves = null; foreach (var obj_ref in obj_refs) { var geometry = obj_ref.Geometry(); if (geometry == null) { return(Result.Failure); } if (geometry is Brep) { curves = Brep.CreateContourCurves(geometry as Brep, base_point, end_point, interval); } else { curves = Mesh.CreateContourCurves(geometry as Mesh, base_point, end_point, interval); } foreach (var curve in curves) { var curve_object_id = doc.Objects.AddCurve(curve); doc.Objects.Select(curve_object_id); } } if (curves != null) { doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // mimic the functionality of the contour command using a background threads // The tricky parts to the contour command are that it dynamically adds // sections as they are found const ObjectType filter = ObjectType.Brep | ObjectType.Extrusion | ObjectType.Mesh; ObjRef[] objrefs; var rc = RhinoGet.GetMultipleObjects("Select objects for contours", false, filter, out objrefs); if (rc != Result.Success) { return(rc); } if (objrefs == null || objrefs.Length < 1) { return(Result.Failure); } Point3d base_point; rc = RhinoGet.GetPoint("Contour plane base point", false, out base_point); if (rc != Result.Success) { return(rc); } var gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Direction perpendicular to contour planes"); gp.DrawLineFromPoint(base_point, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Point3d end_point = gp.Point(); double interval = 1; rc = RhinoGet.GetNumber("Distance between contours", true, ref interval, 0.001, 10000); if (rc != Result.Success) { return(rc); } // figure out the combined bounding box of all the selected geometry BoundingBox bounds = BoundingBox.Unset; var geometries = new List <GeometryBase>(); foreach (var objref in objrefs) { var geometry = objref.Geometry(); var extrusion = geometry as Extrusion; if (extrusion != null) { geometry = objref.Brep(); } geometries.Add(geometry); var bbox = geometry.GetBoundingBox(false); bounds.Union(bbox); } Vector3d normal = end_point - base_point; normal.Unitize(); var curplane = new Plane(base_point, normal); double min_t, max_t; if (!curplane.DistanceTo(bounds, out min_t, out max_t)) { return(Result.Failure); } min_t -= interval; max_t += interval; min_t = Math.Floor(min_t / interval); max_t = Math.Ceiling(max_t / interval); double tolerance = doc.ModelAbsoluteTolerance; var tasks = new List <Task <Curve[]> >(); var gc = new Rhino.Input.Custom.GetCancel(); for (double t = min_t; t <= max_t; t += 1.0) { double offset = t * interval; var point = base_point + normal * offset; var plane = new Plane(point, normal); foreach (var geom in geometries) { var geom1 = geom; var task = Task.Run(() => Section(plane, geom1, tolerance), gc.Token); tasks.Add(task); } } gc.TaskCompleted += OnTaskCompleted; rc = gc.WaitAll(tasks, doc); return(rc); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType filter = ObjectType.Brep | ObjectType.Extrusion | ObjectType.Mesh; var rc = RhinoGet.GetMultipleObjects("Select objects to contour", false, filter, out var objrefs); if (rc != Result.Success) { return(rc); } if (objrefs == null || objrefs.Length < 1) { return(Result.Failure); } rc = RhinoGet.GetPoint("Contour plane base point", false, out var base_point); if (rc != Result.Success) { return(rc); } var gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Direction perpendicular to contour planes"); gp.DrawLineFromPoint(base_point, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var end_point = gp.Point(); var interval = 1.0; rc = RhinoGet.GetNumber("Distance between contours", true, ref interval, 0.001, 10000); if (rc != Result.Success) { return(rc); } var bounds = BoundingBox.Unset; var geometries = new List <GeometryBase>(); foreach (var objref in objrefs) { var geometry = objref.Geometry(); if (geometry is Extrusion) { geometry = objref.Brep(); } geometries.Add(geometry); var bbox = geometry.GetBoundingBox(false); bounds.Union(bbox); } var normal = end_point - base_point; normal.Unitize(); var curplane = new Plane(base_point, normal); if (!curplane.DistanceTo(bounds, out var min_t, out var max_t)) { return(Result.Failure); } min_t -= interval; max_t += interval; min_t = Math.Floor(min_t / interval); max_t = Math.Ceiling(max_t / interval); var tolerance = doc.ModelAbsoluteTolerance; var tasks = new List <Task <Curve[]> >(); var gc = new Rhino.Input.Custom.GetCancel(); for (var t = min_t; t <= max_t; t += 1.0) { var offset = t * interval; var point = base_point + normal * offset; var plane = new Plane(point, normal); foreach (var geom in geometries) { var geom1 = geom; var task = Task.Run(() => Section(plane, geom1, tolerance), gc.Token); tasks.Add(task); } } gc.TaskCompleted += OnTaskCompleted; rc = gc.WaitAll(tasks, doc); return(rc); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.ApplicationSettings.HistorySettings.RecordingEnabled = true; double tolerance = doc.ModelAbsoluteTolerance; GetObject gc = new GetObject(); gc.SetCommandPrompt("Select curve(s) for multipipe"); gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gc.GroupSelect = true; gc.GetMultiple(1, 0); if (gc.CommandResult() != Rhino.Commands.Result.Success) { return(gc.CommandResult()); } List <Curve> curves = new List <Curve>(); for (int i = 0; i < gc.ObjectCount; i++) { Rhino.DocObjects.ObjRef objref = gc.Object(i); Rhino.Geometry.Curve curve = objref.Curve(); curves.Add(curve); ids.Add(objref.ObjectId); } Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber(); gn.SetCommandPrompt("Start and end radius"); int opList = gn.AddOptionList("Cap", caps, capIndex); gn.SetDefaultNumber(radius1); while (true) { Rhino.Input.GetResult get_rc = gn.Get(); if (gn.CommandResult() != Rhino.Commands.Result.Success) { return(gn.CommandResult()); } if (get_rc == Rhino.Input.GetResult.Number) { radius1 = gn.Number(); if (radius1 < 0 || radius1 < 0.0) { Dialogs.ShowMessage("Value must be >= 0.0", "Warning!"); continue; } } else if (get_rc == Rhino.Input.GetResult.Option) { if (gn.OptionIndex() == opList) { capIndex = gn.Option().CurrentListOptionIndex; } continue; } break; } while (true) { RhinoGet.GetNumber("Middle radius", false, ref radius2); if (radius2 <= 0 || radius2 <= 0.0) { Dialogs.ShowMessage("Value must be > 0.0", "Warning!"); continue; } break; } Brep[] pipe; double[] radiParam = { 0.0, 0.5, 1.0 }; double[] radi = { radius1, radius2, radius1 }; PipeCapMode[] pCapM = { PipeCapMode.None, PipeCapMode.Flat, PipeCapMode.Round }; // Create a history record Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, HISTORY_VERSION); WriteHistory(history, ids, radius1, radius2, capIndex); foreach (Curve x in curves) { pipe = Brep.CreatePipe(x, radiParam, radi, true, pCapM[capIndex], true, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceRadians); doc.Objects.AddBrep(pipe[0], null, history, false); doc.Views.Redraw(); } doc.Views.Redraw(); return(Result.Success); }