/// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Define i/o parameters
            var run = false;

            // Read inputs
            if (!DA.GetData(0, ref run))
            {
                return;
            }

            if (run == true)
            {
                ///internal params
                const ObjectType filter = ObjectType.Mesh;
                /// select all meshes in doc
                RhinoGet.GetMultipleObjects("", true, filter, out ObjRef[] objref);

                /// access their materials
                ///
                for (int i = 0; i < objref.Length; i++)
                {
                    var    rhino_object    = objref[i].Object();
                    string new_object_name = rhino_object.GetMaterial(true).ToString();

                    /// set their names
                    ///
                    Name = new_object_name;
                    rhino_object.CommitChanges();
                }
            }
        }
Example #2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var result = RhinoGet.GetMultipleObjects("Select faces", false, Rhino.DocObjects.ObjectType.Surface, out var rhObjects);

            if (result != Result.Success)
            {
                return(result);
            }

            var dialog = new ExportSettingsDialog();

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return(Result.Cancel);
            }

            foreach (var rhObject in rhObjects)
            {
                var geometry = GetGeometry(rhObject.Geometry());

                if (geometry == null)
                {
                    continue;
                }

                dialog.SaveData(geometry);
            }

            return(Result.Success);
        }
Example #3
0
        /// <summary>
        /// launch rhino get object command
        /// </summary>
        /// <param name="parent">parent form that started the command</param>
        /// <param name="ot">selection object type</param>
        /// <returns>array of ObjRef</returns>
        private ObjRef[] PickObj(ObjectType ot = ObjectType.AnyObject)
        {
            WindowState = FormWindowState.Minimized;

            //ObjRef[] picked = await Task.Run(() =>
            //{
            //    Result r = RhinoGet.GetMultipleObjects(" select object(s)", true, ot, out ObjRef[] objs);
            //    if (r == Result.Success)
            //        return objs;
            //    else return new ObjRef[] { };
            //});
            //parent.TopMost = true;
            //parent.BringToFront();
            //return picked;


            Result r = RhinoGet.GetMultipleObjects(" select object(s)", true, ot, out ObjRef[] picked);

            if (r == Result.Success)
            {
                WindowState = FormWindowState.Normal;
                return(picked);
            }
            else
            {
                RhinoApp.WriteLine(" nothing selected...");
                WindowState = FormWindowState.Normal;
                return(new ObjRef[] { });
            }
        }
Example #4
0
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType selFilter = Rhino.DocObjects.ObjectType.Point;

            Rhino.DocObjects.ObjRef[] pointObjRefs;

            Result getPointsResults = RhinoGet.GetMultipleObjects("Select circuit component endpoints",
                                                                  false, selFilter, out pointObjRefs);

            if (getPointsResults == Result.Success)
            {
                RhinoList <Point> circuitPoints = new RhinoList <Point>();
                foreach (Rhino.DocObjects.ObjRef objRef in pointObjRefs)
                {
                    circuitPoints.Add(objRef.Point());
                }

                RhinoList <Line> conduitLines = autoroute(circuitPoints);
                foreach (Line conduitLine in conduitLines)
                {
                    doc.Objects.AddLine(conduitLine);
                }
                doc.Views.Redraw();
                return(Result.Success);
            }

            return(Result.Failure);
        }
    public static Result ExtendCurve(RhinoDoc doc)
    {
        ObjRef[] boundary_obj_refs;
        var      rc = RhinoGet.GetMultipleObjects("Select boundary objects", false, ObjectType.AnyObject, out boundary_obj_refs);

        if (rc != Result.Success)
        {
            return(rc);
        }
        if (boundary_obj_refs == null || boundary_obj_refs.Length == 0)
        {
            return(Result.Nothing);
        }

        var gc = new GetObject();

        gc.SetCommandPrompt("Select curve to extend");
        gc.GeometryFilter          = ObjectType.Curve;
        gc.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
        gc.DisablePreSelect();
        gc.Get();
        if (gc.CommandResult() != Result.Success)
        {
            return(gc.CommandResult());
        }
        var curve_obj_ref = gc.Object(0);

        var curve = curve_obj_ref.Curve();

        if (curve == null)
        {
            return(Result.Failure);
        }
        double t;

        if (!curve.ClosestPoint(curve_obj_ref.SelectionPoint(), out t))
        {
            return(Result.Failure);
        }
        var curve_end = t <= curve.Domain.Mid ? CurveEnd.Start : CurveEnd.End;

        var geometry       = boundary_obj_refs.Select(obj => obj.Geometry());
        var extended_curve = curve.Extend(curve_end, CurveExtensionStyle.Line, geometry);

        if (extended_curve != null && extended_curve.IsValid)
        {
            if (!doc.Objects.Replace(curve_obj_ref.ObjectId, extended_curve))
            {
                return(Result.Failure);
            }
            doc.Views.Redraw();
        }
        else
        {
            RhinoApp.WriteLine("No boundary object was intersected so curve not extended");
            return(Result.Nothing);
        }

        return(Result.Success);
    }
    public static Result ProjectPointsToMeshesEx(RhinoDoc doc)
    {
        ObjRef obj_ref;
        var    rc = RhinoGet.GetOneObject("mesh", false, ObjectType.Mesh, out obj_ref);

        if (rc != Result.Success)
        {
            return(rc);
        }
        var mesh = obj_ref.Mesh();

        ObjRef[] obj_ref_pts;
        rc = RhinoGet.GetMultipleObjects("points", false, ObjectType.Point, out obj_ref_pts);
        if (rc != Result.Success)
        {
            return(rc);
        }
        var points = new List <Point3d>();

        foreach (var obj_ref_pt in obj_ref_pts)
        {
            var pt = obj_ref_pt.Point().Location;
            points.Add(pt);
        }

        int[] indices;
        var   prj_points = Intersection.ProjectPointsToMeshesEx(new[] { mesh }, points, new Vector3d(0, 1, 0), 0, out indices);

        foreach (var prj_pt in prj_points)
        {
            doc.Objects.AddPoint(prj_pt);
        }
        doc.Views.Redraw();
        return(Result.Success);
    }
Example #7
0
        public override void Setup() // this runs once in the beginning.
        {
            ObjectType.Curve;
            RhinoGet.GetMultipleObjects("select rectangle", true, , crv);

            for (int i = 0; i < crv.Length; i++)
            {
                crv[i].Z = 300;
            }
        }
Example #8
0
        //PickPoint 選點功能
        public Result RunCommand(RhinoDoc doc)
        {
            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);

            //選擇多點
            ObjRef[] obj_refs;
            rc = RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs);
            if (rc != Result.Success)
            {
                return(rc);
            }

            //欄位名稱
            TxtRes.Text = "BC,UR1,UR2,UR3\n";
            int i = 0;

            //清空
            CbPointX.Items.Clear();
            CbPointY.Items.Clear();
            CbPointZ.Items.Clear();

            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);

                i++;
                //迭代
                TxtRes.Text += TxtInputBC.Text + i + "," +
                               point.Location.X + "," +
                               point.Location.Y + "," +
                               point.Location.Z + ",\n";

                CbPointX.Items.Add(point.Location.X);
                CbPointY.Items.Add(point.Location.Y);
                CbPointZ.Items.Add(point.Location.Z);
            }
            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);
        }
Example #10
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var filter = ObjectType.Curve;

            ObjRef[] obj_refs;

            var rc = RhinoGet.GetMultipleObjects("Select objects to offset", false, filter, out obj_refs);

            if (rc != Result.Success)
            {
                return(rc);
            }
            return(Result.Nothing);
        }
Example #11
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            TablDockPanel tablpanel = Panels.GetPanel <TablDockPanel>(RhinoDoc.ActiveDoc);
            bool          blitz     = false;
            var           r         = RhinoGet.GetBool(" Erase existing Tabl_ contents?", false, "No", "Yes", ref blitz);

            if (r == Result.Success)
            {
                r = RhinoGet.GetMultipleObjects(" Select objects to add", true, ObjectType.AnyObject, out ObjRef[] picked);
                if (r == Result.Success)
                {
                    if (blitz)
                    {
                        tablpanel.Loaded = picked.Select(oref => new ObjRef(oref.ObjectId)).ToArray();
                        tablpanel.PushRefs();
                    }
                    else
                    {
                        List <ObjRef> concat = new List <ObjRef>();
                        concat.AddRange(tablpanel.Loaded);
                        var ids = tablpanel.Loaded.Select(i => i.ObjectId.ToString());
                        foreach (ObjRef oref in picked)
                        {
                            if (!ids.Contains(oref.ObjectId.ToString()))
                            {
                                concat.Add(new ObjRef(oref.ObjectId));
                            }
                        }
                        tablpanel.Loaded = concat.ToArray();
                        tablpanel.PushRefs();
                    }
                    tablpanel.Refresh_Click(null, null); // dummy args, method doesn't use them anyway
                    if (!Panels.IsPanelVisible(TablDockPanel.PanelId))
                    {
                        MessageBox.Show("Added to Tabl_\nType \"LaunchTabl_\" to open it", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    RhinoApp.WriteLine("command interrupted, nothing done...");
                }
            }
            else
            {
                RhinoApp.WriteLine("command interrupted, nothing done...");
            }

            return(Result.Success);
        }
Example #12
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var analysis_mode = VisualAnalysisMode.Find(typeof(SampleCsZAnalysisMode));

            if (null == analysis_mode)
            {
                analysis_mode = VisualAnalysisMode.Register(typeof(SampleCsZAnalysisMode));
            }
            if (null == analysis_mode)
            {
                RhinoApp.WriteLine("Unable to register Z-Analysis mode.");
                return(Result.Failure);
            }

            const ObjectType filter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh;
            var rc = RhinoGet.GetMultipleObjects("Select objects for Z analysis", false, filter, out var obj_refs);

            if (rc != Result.Success)
            {
                return(rc);
            }

            var count = 0;

            foreach (var obj_ref in obj_refs)
            {
                var obj = obj_ref.Object();

                // see if this object is already in Z-Analysis mode
                if (obj.InVisualAnalysisMode(analysis_mode))
                {
                    continue;
                }

                if (obj.EnableVisualAnalysisMode(analysis_mode, true))
                {
                    count++;
                }
            }

            doc.Views.Redraw();
            RhinoApp.WriteLine("{0} object(s) set into Z-Analysis mode.", count);

            return(Result.Success);
        }
Example #13
0
        public Result RunCommand(RhinoDoc doc)
        {
            //選擇多點
            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)
            {
                point = o_ref.Point();
                RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}",
                                   point.Location.X,
                                   point.Location.Y,
                                   point.Location.Z);
            }
            return(Result.Success);
        }
Example #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef[] obj_refs;
            var      rc = RhinoGet.GetMultipleObjects("Select hatches to replace", false, ObjectType.Hatch, out obj_refs);

            if (rc != Result.Success || obj_refs == null)
            {
                return(rc);
            }

            var gs = new GetString();

            gs.SetCommandPrompt("Name of replacement hatch pattern");
            gs.AcceptNothing(false);
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }
            var hatch_name = gs.StringResult();

            var pattern_index = doc.HatchPatterns.Find(hatch_name, true);

            if (pattern_index < 0)
            {
                RhinoApp.WriteLine("The hatch pattern \"{0}\" not found  in the document.", hatch_name);
                return(Result.Nothing);
            }

            foreach (var obj_ref in obj_refs)
            {
                var hatch_object = obj_ref.Object() as HatchObject;
                if (hatch_object.HatchGeometry.PatternIndex != pattern_index)
                {
                    hatch_object.HatchGeometry.PatternIndex = pattern_index;
                    hatch_object.CommitChanges();
                }
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
Example #15
0
    public static Result ReverseCurve(RhinoDoc doc)
    {
        ObjRef[] obj_refs;
        var      rc = RhinoGet.GetMultipleObjects("Select curves to reverse", true, ObjectType.Curve, out obj_refs);

        if (rc != Result.Success)
        {
            return(rc);
        }

        foreach (var obj_ref in obj_refs)
        {
            var curve_copy = obj_ref.Curve().DuplicateCurve();
            if (curve_copy != null)
            {
                curve_copy.Reverse();
                doc.Objects.Replace(obj_ref, curve_copy);
            }
        }
        return(Result.Success);
    }
Example #16
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef[] obj_refs;
            var      rc = RhinoGet.GetMultipleObjects("Select points to move", false, ObjectType.Point, out obj_refs);

            if (rc != Result.Success || obj_refs == null)
            {
                return(rc);
            }

            var gp = new GetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            var start_point = gp.Point();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(start_point, false);
            gp.DrawLineFromPoint(start_point, true);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }
            var end_point = gp.Point();

            var xform = Transform.Translation(end_point - start_point);

            foreach (var obj_ref in obj_refs)
            {
                doc.Objects.Transform(obj_ref, xform, true);
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
Example #17
0
        public static Result GetFloors(RhinoDoc rhinoDocument)
        {
            ObjRef[] objRefArray;
            Result   multipleObjects = RhinoGet.GetMultipleObjects("Please select surfaces", false, (ObjectType)2097160, out objRefArray);

            if (multipleObjects != null)
            {
                return(multipleObjects);
            }
            if (objRefArray == null || objRefArray.Length < 1)
            {
                return((Result)3);
            }
            string str = "#VR User Defined Floors";
            int    num = rhinoDocument.Layers.Find(str, true);

            if (num < 0)
            {
                LayerTable layers = rhinoDocument.Layers;
                num = layers.Add(str, Color.Black);
                if (num < 0)
                {
                    RhinoApp.WriteLine("Unable to add <{0}> layer.", (object)str);
                    return((Result)3);
                }
                Layer layer = layers[num];
                layer.Color = (Color.Blue);
                layer.CommitChanges();
            }
            for (int index = 0; index < objRefArray.Length; ++index)
            {
                RhinoObject rhinoObject = objRefArray[index].Object();
                rhinoObject.Attributes.LayerIndex = num;
                rhinoObject.CommitChanges();
            }
            rhinoDocument.Views.Redraw();
            return((Result)0);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef[] objrefs;
            var      rc = RhinoGet.GetMultipleObjects("Select objects to group", false, ObjectType.AnyObject, out objrefs);

            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }
            if (objrefs == null || objrefs.Length < 1)
            {
                return(Result.Failure);
            }

            var guids = new List <Guid>(objrefs.Length);

            guids.AddRange(objrefs.Select(objref => objref.ObjectId));

            doc.Groups.Add(guids);
            doc.Views.Redraw();

            return(Result.Success);
        }
Example #19
0
    public static Result MovePointObjectsNonUniform(RhinoDoc doc)
    {
        ObjRef[] obj_refs;
        var      rc = RhinoGet.GetMultipleObjects("Select points to move", false, ObjectType.Point, out obj_refs);

        if (rc != Result.Success || obj_refs == null)
        {
            return(rc);
        }

        foreach (var obj_ref in obj_refs)
        {
            var point3d = obj_ref.Point().Location;
            // modify the point coordinates in some way ...
            point3d.X++;
            point3d.Y++;
            point3d.Z++;

            doc.Objects.Replace(obj_ref, point3d);
        }

        doc.Views.Redraw();
        return(Result.Success);
    }
Example #20
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef[] obj_refs;
            var      rc = RhinoGet.GetMultipleObjects("Select points to move", false, ObjectType.Point, out obj_refs);

            if (rc != Result.Success || obj_refs == null)
            {
                return(rc);
            }

            foreach (var obj_ref in obj_refs)
            {
                var point3d = obj_ref.Point().Location;
                // modify the point coordinates in some way ...
                point3d.X++;
                point3d.Y++;
                point3d.Z++;

                doc.Objects.Replace(obj_ref, point3d);
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
Example #21
0
        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);
        }
Example #22
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoApp.WriteLine("The {0} will construct JSON representation of your scene.", EnglishName);

            Rhino.DocObjects.ObjRef[] objrefs;
            Result rc = RhinoGet.GetMultipleObjects("Select your scene objects",
                                                    false, Rhino.DocObjects.ObjectType.AnyObject, out objrefs);

            List <Element> allElements = new List <Element>();

            if (objrefs?.Length > 0)
            {
                foreach (var obj in objrefs)
                {
                    var             material  = obj.Object().GetMaterial(true);
                    var             mesh      = new va3c_Mesh();
                    Mesh            finalMesh = new Mesh();
                    RCva3c.Material mat;
                    if (material != null)
                    {
                        mat = new va3c_MeshPhongMaterial().GeneratePhongMaterial(material.DiffuseColor, material.AmbientColor, material.EmissionColor, material.SpecularColor, material.Shine, 1 - material.Transparency);
                    }
                    else
                    {
                        mat = new va3c_MeshBasicMaterial().GenerateMaterial(System.Drawing.Color.White, 1);
                    }

                    switch (obj.Geometry().ObjectType)
                    {
                    case ObjectType.None:
                        break;

                    case ObjectType.Point:
                        break;

                    case ObjectType.PointSet:
                        break;

                    case ObjectType.Curve:
                        break;

                    case ObjectType.Surface:
                        var srf     = obj.Surface();
                        var meshSrf = Mesh.CreateFromBrep(srf.ToBrep());
                        if (meshSrf?.Length > 0)
                        {
                            foreach (var m in meshSrf)
                            {
                                finalMesh.Append(m);
                            }
                        }
                        allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, new List <string> {
                            ObjectType.Brep.ToString()
                        }, new List <string> {
                            ObjectType.Brep.ToString()
                        }));
                        break;

                    case ObjectType.Brep:
                        var brep     = obj.Brep();
                        var meshBrep = Mesh.CreateFromBrep(brep);
                        if (meshBrep?.Length > 0)
                        {
                            foreach (var m in meshBrep)
                            {
                                finalMesh.Append(m);
                            }
                        }
                        allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, new List <string> {
                            "objectId"
                        }, new List <string> {
                            obj.ObjectId.ToString()
                        }));
                        break;

                    case ObjectType.Mesh:
                        var msh = obj.Mesh();
                        allElements.Add(mesh.GenerateMeshElement(msh, mat, new List <string> {
                            "objectId"
                        }, new List <string> {
                            obj.ObjectId.ToString()
                        }));
                        break;

                    case ObjectType.Light:
                        break;

                    case ObjectType.Annotation:
                        break;

                    case ObjectType.InstanceDefinition:
                        break;

                    case ObjectType.InstanceReference:
                        break;

                    case ObjectType.TextDot:
                        break;

                    case ObjectType.Grip:
                        break;

                    case ObjectType.Detail:
                        break;

                    case ObjectType.Hatch:
                        break;

                    case ObjectType.MorphControl:
                        break;

                    case ObjectType.BrepLoop:
                        break;

                    case ObjectType.PolysrfFilter:
                        break;

                    case ObjectType.EdgeFilter:
                        break;

                    case ObjectType.PolyedgeFilter:
                        break;

                    case ObjectType.MeshVertex:
                        break;

                    case ObjectType.MeshEdge:
                        break;

                    case ObjectType.MeshFace:
                        break;

                    case ObjectType.Cage:
                        break;

                    case ObjectType.Phantom:
                        break;

                    case ObjectType.ClipPlane:
                        break;

                    case ObjectType.Extrusion:

                        var extruction     = obj.Brep();
                        var meshExtruction = Mesh.CreateFromBrep(extruction);
                        if (meshExtruction?.Length > 0)
                        {
                            foreach (var m in meshExtruction)
                            {
                                finalMesh.Append(m);
                            }
                        }
                        allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, new List <string> {
                            "objectId"
                        }, new List <string> {
                            obj.ObjectId.ToString()
                        }));
                        break;

                    case ObjectType.AnyObject:
                        break;

                    default:
                        break;
                    }
                }
            }

            var        scenecompiler = new va3c_SceneCompiler();
            string     resultatas    = scenecompiler.GenerateSceneJson(allElements);
            Filewriter writer        = new Filewriter();

            writer.SaveFileTo(new List <string> {
                resultatas
            });
            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select houses
            ObjRef[] buildingRefs;
            Result   rc0 = Rhino.Input.RhinoGet.GetMultipleObjects("Select Buildings to be connected", true, ObjectType.Brep, out buildingRefs);

            if (rc0 != Rhino.Commands.Result.Success)
            {
                return(rc0);
            }
            if (buildingRefs == null || buildingRefs.Length < 1)
            {
                return(Rhino.Commands.Result.Failure);
            }

            List <Rhino.Geometry.Brep> in_breps0 = new List <Rhino.Geometry.Brep>();

            for (int i = 0; i < buildingRefs.Length; i++)
            {
                Rhino.Geometry.Brep brep = buildingRefs[i].Brep();
                if (brep != null)
                {
                    in_breps0.Add(brep);
                }
            }

            doc.Objects.UnselectAll();

            // Select 1 Thermal Plant
            ObjRef[] plantRefs;
            Result   rc1 = RhinoGet.GetMultipleObjects("Select 1 Thermal Plant", true, ObjectType.Brep, out plantRefs);

            if (rc1 != Result.Success)
            {
                return(rc1);
            }
            if (plantRefs == null || plantRefs.Length < 1)
            {
                return(Result.Failure);
            }

            List <Rhino.Geometry.Brep> in_breps1 = new List <Rhino.Geometry.Brep>();

            for (int i = 0; i < plantRefs.Length; i++)
            {
                Rhino.Geometry.Brep brep = plantRefs[i].Brep();
                if (brep != null)
                {
                    in_breps1.Add(brep);
                }
            }

            doc.Objects.UnselectAll();

            RhinoApp.WriteLine("{0} buildings and {1} thermal plant added", in_breps0.Count, in_breps1.Count);

            // Create lines between all buildings and thermal plant

            List <double> XcoordinatesBuildings = new List <double>();
            List <double> YcoordinatesBuildings = new List <double>();

            for (int i = 0; i < in_breps0.Count; i++)
            {
                for (int j = 0; i < in_breps0.Count; i++)
                {
                    VolumeMassProperties vmp0 = VolumeMassProperties.Compute(buildingRefs[i].Brep());
                    VolumeMassProperties vmp1 = VolumeMassProperties.Compute(plantRefs[j].Brep());
                    //XcoordinatesBuildings[i] = vmp0.Centroid.X;
                    //YcoordinatesBuildings[i] = vmp0.Centroid.Y;

                    Point3d  pt_start = new Point3d(vmp0.Centroid.X, vmp0.Centroid.Y, 0);
                    Point3d  pt_end   = new Point3d(vmp1.Centroid.X, vmp1.Centroid.Y, 0);
                    Vector3d v        = new Vector3d(pt_end - pt_start);
                    if (v.IsTiny(Rhino.RhinoMath.ZeroTolerance))
                    {
                        return(Rhino.Commands.Result.Nothing);
                    }

                    if (doc.Objects.AddLine(pt_start, pt_end) != Guid.Empty)
                    {
                        doc.Views.Redraw();
                        //return Rhino.Commands.Result.Success;
                    }
                }
            }

            return(Result.Success);
        }
Example #24
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef[] objRefsA;
            // RhinoApp.WriteLine("Hi there!!");
            var rc = RhinoGet.GetMultipleObjects("Select set of curves to Boolean (A)", false, ObjectType.Curve, out objRefsA);

            if (rc != Result.Success)
            {
                return(rc);
            }

            var getB = new Rhino.Input.Custom.GetObject();

            getB.AcceptNothing(false);
            getB.GeometryFilter = ObjectType.Curve;
            getB.SetCommandPrompt("Select second set of curves to Boolean (B)");
            getB.DisablePreSelect(); //<-- disable pre-selection on second get object
            var result = getB.GetMultiple(1, 0);

            if (result != GetResult.Object)
            {
                return(rc);
            }

            // Convert curves to polylines. Perhaps this should have more control?
            var curvesA = Polyline3D.ConvertCurvesToPolyline(objRefsA.Select(r => r.Curve()));
            var curvesB = Polyline3D.ConvertCurvesToPolyline(getB.Objects().Select(r => r.Curve()));

            if (_options == null)
            {
                _options = new PolylineBooleanOptions();
                _options.Initialize(doc.ModelAbsoluteTolerance, mode.Equals(RunMode.Scripted));
                _options.SetCommandPrompt("Select boolean type (click to toggle)");
                _options.AcceptNothing(true);
            }

            _options.EnableTransparentCommands(true);
            _options.SetOriginalCurves(curvesA, curvesB);

            while (true)
            {
                var res = _options.Get();
                RhinoApp.WriteLine(res.ToString());

                if (res == GetResult.Point)
                {
                    _options.ToggleBoolean();
                }

                if (res == GetResult.Cancel)
                {
                    return(_options.CommandResult());
                }

                if (res == GetResult.Nothing)
                {
                    break;
                }

                if (res == GetResult.Option)
                {
                    // update the enum options
                    _options.UpdateOptions();
                    _options.CalculateBoolean();
                }
            }

            // deleselect all.
            doc.Objects.Select(doc.Objects.GetSelectedObjects(true, true).Select(obj => obj.Id), false);
            // return the offset
            var guids = _options.Results.Select(pl => doc.Objects.AddPolyline(pl));

            doc.Objects.Select(guids);
            return(Result.Success);
        }
    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);
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var ptPuffynessOption       = new OptionToggle(m_PointPuffyness, "False", "True");
            var ptOffsetOption          = new OptionDouble(m_PuffynessOffset, 0.5, double.PositiveInfinity);
            var ptBorderPuffynessOption = new OptionToggle(m_BorderPuffyness, "False", "True");
            var borderOffsetOption      = new OptionDouble(m_BorderOffset, 0.5, double.PositiveInfinity);

            var go = new GetOption();

            go.SetCommandPrompt("Get meshing properties");
            go.AcceptNothing(true);
            go.AcceptEnterWhenDone(true);

            int ptPuffyOptionIndex      = go.AddOptionToggle("PointPuffyness", ref ptPuffynessOption);
            int offsetOptionIndex       = go.AddOptionDouble("OffsetPtPuffy", ref ptOffsetOption);
            int borderPuffyOptionIndex  = go.AddOptionToggle("BorderPuffyness", ref ptBorderPuffynessOption);
            int borderOffsetOptionIndex = go.AddOptionDouble("OffsetBorderPuffy", ref borderOffsetOption);

            go.Get();
            var result = go.Result();

            while (result != GetResult.Nothing)
            {
                if (result == GetResult.Cancel)
                {
                    return(Result.Cancel);
                }

                int optionIdx = go.OptionIndex();
                if (optionIdx == ptPuffyOptionIndex)
                {
                    m_PointPuffyness = ptPuffynessOption.CurrentValue;
                }
                else if (optionIdx == offsetOptionIndex)
                {
                    m_PuffynessOffset = ptOffsetOption.CurrentValue;
                }
                else if (optionIdx == borderPuffyOptionIndex)
                {
                    m_BorderPuffyness = ptBorderPuffynessOption.CurrentValue;
                }
                else if (optionIdx == borderOffsetOptionIndex)
                {
                    m_BorderOffset = borderOffsetOption.CurrentValue;
                }

                result = go.Get();
            }

            ObjRef[] rhObjects;
            var      res = RhinoGet.GetMultipleObjects("Select planar curves and Weight points", false, Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Point, out rhObjects);

            if (res == Result.Success)
            {
                // 1. subdive in sets: Closed curves, Opened Curves, weight points;
                List <Curve> closed_crvs   = new List <Curve>();
                List <Curve> opened_crvs   = new List <Curve>();
                List <Point> weight_points = new List <Point>();

                bool   puffyness = m_PointPuffyness;
                double offset    = m_PuffynessOffset;

                bool   border_puffyness = m_BorderPuffyness;
                double border_offset    = m_BorderOffset;

                foreach (var ref_obj in rhObjects)
                {
                    RhinoObject obj = ref_obj.Object();
                    if (obj.Geometry is Curve)
                    {
                        var crv = obj.Geometry as Curve;
                        if (crv.IsPlanar())
                        {
                            if (crv.IsClosed)
                            {
                                closed_crvs.Add(crv);
                            }
                            else
                            {
                                opened_crvs.Add(crv);
                            }
                        }
                    }
                    else if (obj.Geometry is Point)
                    {
                        weight_points.Add(obj.Geometry as Point);
                    }
                }

                double space = 1;

                // 2. Insert curves into mesh
                AM_Region region = null;

                Curve border_outer_crv = null;
                Curve offset_outer_crv = null;

                if (closed_crvs.Count > 0)
                {
                    region = new AM_Region();

                    for (int i = 0; i < closed_crvs.Count; i++)
                    {
                        var crv = closed_crvs[i];

                        region.AddCurve(crv, space, false);

                        AreaMassProperties area = AreaMassProperties.Compute(crv, AM_Util.FLT_EPSILON);
                        if (area.Area > 0 && border_puffyness)
                        {
                            if (border_outer_crv == null)
                            {
                                border_outer_crv = crv;
                            }

                            var offset_Crvs = crv.Offset(Plane.WorldXY, -border_offset, AM_Util.FLT_EPSILON, CurveOffsetCornerStyle.None);

                            foreach (var c in offset_Crvs)
                            {
                                c.Reverse();
                                doc.Objects.AddCurve(c);
                                offset_outer_crv = c;

                                region.AddCurve(c, space, true);
                            }
                        }
                    }
                }
                else
                {
                    // TODO
                    Debug.Assert(false);
                    return(Result.Failure);
                }

                for (int i = 0; i < weight_points.Count; i++)
                {
                    var pt = weight_points[i];

                    region.AddWeigthPoint(pt, space / 2);
                    if (puffyness && offset > 0)
                    {
                        var circle = new ArcCurve(new Circle(pt.Location, offset));
                        var nurbs  = circle.ToNurbsCurve();
                        region.AddCurve(nurbs, space / 2, true);
                    }
                }

                for (int i = 0; i < opened_crvs.Count; i++)
                {
                    var crv = opened_crvs[i];
                    region.AddCurve(crv, space, false);

                    if (puffyness && offset > 0)
                    {
                        var     n         = Vector3d.CrossProduct(crv.TangentAtStart, Vector3d.ZAxis);
                        Curve[] offsetCrv = crv.Offset(crv.PointAtStart + offset * n, Vector3d.ZAxis, offset, AM_Util.FLT_EPSILON, CurveOffsetCornerStyle.Round);

                        foreach (var c in offsetCrv)
                        {
                            doc.Objects.AddCurve(c);
                            region.AddCurve(crv, space, false);
                        }

                        Curve[] offsetCrv2 = crv.Offset(crv.PointAtStart - offset * n, Vector3d.ZAxis, offset, AM_Util.FLT_EPSILON, CurveOffsetCornerStyle.Round);

                        foreach (var c in offsetCrv2)
                        {
                            doc.Objects.AddCurve(c);
                            region.AddCurve(crv, space, false);
                        }
                    }
                }

                // 3. Mesh della regione
                if (region != null)
                {
                    if (region.BuildMesh())
                    {
                        // Inserisce i punti del contorno
                        foreach (var loop in region.Loops)
                        {
                            for (int i = 0; i < loop.NumSegments; i++)
                            {
                                var points = loop.GetGeneratedPoints(i);

                                //if (points != null) {
                                //  foreach (var p in points) {
                                //    doc.Objects.AddPoint(new Point3d(p.X, p.Y, 0));
                                //  }
                                //}
                            }
                        }
                    }

                    // Trasforma in Mesh di Rhino
                    var mesh = region.Mesh2D;

                    if (mesh != null)
                    {
                        Mesh   rhino_mesh = new Mesh();
                        double t          = 5;
                        for (int i = 0; i < mesh.ArrayVertexes.Count; i++)
                        {
                            mesh.ArrayVertexes[i].Z = t;
                        }

                        // PostProcessa il puffyness
                        if (puffyness)
                        {
                            for (int i = 0; i < region.ArrayInnerVertex.Count; i++)
                            {
                                var iv = region.ArrayInnerVertex[i];
                                if (iv.MeshVertex != null)
                                {
                                    iv.MeshVertex.Z = (4 / 5d) * t;
                                }

                                // Ricerca i punti nell'intorno fino all'offset (molto grezza!)
                                for (int j = 0; j < mesh.ArrayVertexes.Count; j++)
                                {
                                    var    v = mesh.ArrayVertexes[j];
                                    double d = (iv.MeshVertex.Coord - v.Coord).Length;
                                    if (d < offset)
                                    {
                                        double r = d / offset;

                                        AM_Util.EInterpolation interpolation = AM_Util.EInterpolation.Parabolic;
                                        v.Z = AM_Util.Interpolation(interpolation, iv.MeshVertex.Z, t, r);
                                    }
                                }
                            }
                        }

                        // Individua i punti all'interno della zona di transizione
                        List <int> transitionVts = new List <int>();

                        if (border_puffyness && border_offset > 0)
                        {
                            // Individua i vertici di partenza e utilizza u flag di lavoro
                            List <AM_Vertex> transitionStartVts = new List <AM_Vertex>();

                            for (int i = 0; i < mesh.ArrayVertexes.Count; i++)
                            {
                                var  v = mesh.ArrayVertexes[i];
                                bool is_loop_vertex = (v.Flag & 0x1) > 0;
                                v.Flag &= ~0x02;

                                if (is_loop_vertex && BelongToBorder(v))
                                {
                                    transitionStartVts.Add(v);
                                }
                            }

                            // Si usa 0x04 come flag di lavoro
                            for (int i = 0; i < mesh.ArrayWEdges.Count; i++)
                            {
                                var e                 = mesh.ArrayWEdges[i];
                                e.Edge().Flag        &= ~0x04;
                                e.Edge().Symm().Flag &= ~0x04;
                            }

                            for (int i = 0; i < transitionStartVts.Count; i++)
                            {
                                var v = transitionStartVts[i];
                                AddTransitionVertexes(v, transitionVts);
                            }

                            if (offset_outer_crv != null)
                            {
                                foreach (var iv in transitionVts)
                                {
                                    var v = mesh.ArrayVertexes[iv];

                                    double par;
                                    if (offset_outer_crv.ClosestPoint(AM_Util.To3d(v.Coord), out par, 2 * border_offset))
                                    {
                                        Point3d cp = offset_outer_crv.PointAt(par);
                                        double  r  = ((cp - AM_Util.To3d(v.Coord)).Length) / border_offset;
                                        double  z  = AM_Util.Interpolation(AM_Util.EInterpolation.Parabolic, 0.8 * t, t, 1 - r);
                                        v.Z = z;
                                    }
                                }
                            }
                        }

                        // Facce
                        int totVtx = mesh.ArrayVertexes.Count;

                        for (int iSide = 0; iSide < 2; iSide++)
                        {
                            for (int i = 0; i < mesh.ArrayVertexes.Count; i++)
                            {
                                var     v  = mesh.ArrayVertexes[i];
                                Point3d pt = v.Coord3d;
                                if (iSide == 1)
                                {
                                    pt.Z = 0;
                                }

                                rhino_mesh.Vertices.Add(pt);
                            }

                            for (int i = 0; i < mesh.ArrayFaces.Count; i++)
                            {
                                var f = mesh.ArrayFaces[i];

                                int numEdges = f.NumEdges;
                                if (numEdges == 3)
                                {
                                    int[] vtx = { f.Vertex(0).Index, f.Vertex(1).Index, f.Vertex(2).Index };
                                    if (iSide == 1)
                                    {
                                        vtx = new int[] { f.Vertex(0).Index + totVtx, f.Vertex(2).Index + totVtx, f.Vertex(1).Index + totVtx };
                                    }
                                    rhino_mesh.Faces.AddFace(vtx[0], vtx[1], vtx[2]);
                                }
                                else if (numEdges == 4)
                                {
                                    int[] vtx = { f.Vertex(0).Index, f.Vertex(1).Index, f.Vertex(2).Index, f.Vertex(3).Index };
                                    if (iSide == 1)
                                    {
                                        vtx = new int[] { f.Vertex(0).Index + totVtx, f.Vertex(3).Index + totVtx, f.Vertex(2).Index + totVtx, f.Vertex(1).Index + totVtx };
                                    }

                                    rhino_mesh.Faces.AddFace(vtx[0], vtx[1], vtx[2], vtx[3]);
                                }
                            }
                        }

                        for (int iEdge = 0; iEdge < mesh.ArrayWEdges.Count; iEdge++)
                        {
                            var edge = mesh.ArrayWEdges[iEdge].Edge();
                            if (edge.CcwFace() == null || edge.CwFace() == null)
                            {
                                // E' uno spigolo di bordo
                                int[] vtx = { edge.Destination().Index,     edge.Origin().Index,
                                              edge.Origin().Index + totVtx, edge.Destination().Index + totVtx, };
                                rhino_mesh.Faces.AddFace(vtx[0], vtx[1], vtx[2], vtx[3]);
                            }
                        }

                        rhino_mesh.Normals.ComputeNormals();
                        rhino_mesh.Compact();
                        if (doc.Objects.AddMesh(rhino_mesh) != Guid.Empty)
                        {
                            doc.Views.Redraw();
                            return(Rhino.Commands.Result.Success);
                        }
                    }
                }

                return(Result.Success);
            }


            return(Result.Cancel);
        }
Example #27
0
    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);
    }
Example #28
0
    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);
    }
Example #29
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //First, collect all the breps to split
            ObjRef[] obj_refs;
            var      rc = RhinoGet.GetMultipleObjects("Select breps to split", false, ObjectType.Brep, out obj_refs);

            if (rc != Result.Success || obj_refs == null)
            {
                return(rc);
            }

            // Get the final plane
            Plane plane;

            rc = RhinoGet.GetPlane(out plane);
            if (rc != Result.Success)
            {
                return(rc);
            }

            //Iterate over all object references
            foreach (var obj_ref in obj_refs)
            {
                var brep = obj_ref.Brep();
                var bbox = brep.GetBoundingBox(false);

                //Grow the boundingbox in all directions
                //If the boundingbox is flat (zero volume or even zero area)
                //then the CreateThroughBox method will fail.
                var min_point = bbox.Min;
                min_point.X -= 1.0;
                min_point.Y -= 1.0;
                min_point.Z -= 1.0;
                bbox.Min     = min_point;
                var max_point = bbox.Max;
                max_point.X += 1.0;
                max_point.Y += 1.0;
                max_point.Z += 1.0;
                bbox.Max     = max_point;

                var plane_surface = PlaneSurface.CreateThroughBox(plane, bbox);
                if (plane_surface == null)
                {
                    //This is rare, it will most likely not happen unless either the plane or the boundingbox are invalid
                    RhinoApp.WriteLine("Cutting plane could not be constructed.");
                }
                else
                {
                    var breps = brep.Split(plane_surface.ToBrep(), doc.ModelAbsoluteTolerance);
                    if (breps == null || breps.Length == 0)
                    {
                        RhinoApp.Write("Plane does not intersect brep (id:{0})", obj_ref.ObjectId);
                        continue;
                    }
                    foreach (var brep_piece in breps)
                    {
                        doc.Objects.AddBrep(brep_piece);
                    }
                    doc.Objects.AddSurface(plane_surface);
                    doc.Objects.Delete(obj_ref, false);
                }
            }

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