Example #1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Mesh;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select mesh to contour", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Mesh mesh = objref.Geometry() as Rhino.Geometry.Mesh;
            if (null == mesh)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.BoundingBox bbox     = mesh.GetBoundingBox(false);
            Rhino.Geometry.Point3d     start_pt = bbox.Corner(true, true, true);
            Rhino.Geometry.Point3d     end_pt   = bbox.Corner(false, true, true);
            double interval = start_pt.DistanceTo(end_pt) / 10;

            Rhino.Geometry.Curve[] curves = Rhino.Geometry.Mesh.CreateContourCurves(mesh, start_pt, end_pt, interval);
            if (null != curves && curves.Length > 0)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    doc.Objects.AddCurve(curves[i]);
                }
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
Example #2
0
 void CalMat(RhinoDoc doc, double spezWeight, Rhino.DocObjects.ObjectType objType, Rhino.DocObjects.ObjRef objref, List <string> matList, String[] matName, int pos, string g_ct)
 {
     if ((objType == Rhino.DocObjects.ObjectType.Surface | objType == Rhino.DocObjects.ObjectType.PolysrfFilter | objType == Rhino.DocObjects.ObjectType.Brep | objType == Rhino.DocObjects.ObjectType.Extrusion))
     {
         Brep objrefBrep = objref.Brep();
         bool bc         = objrefBrep.IsSolid;
         if (bc == false)
         {
             open++;
         }
         double volObj = objrefBrep.GetVolume();
         double weight = Math.Round(volObj * spezWeight, 3, MidpointRounding.AwayFromZero);
         materials[pos] += weight;
         //matList.Add(matName[pos] + " " + weight + g_ct);
     }
     else if (objType == Rhino.DocObjects.ObjectType.Mesh)
     {
         Mesh objrefMesh = objref.Mesh();
         bool bc         = objrefMesh.IsClosed;
         if (bc == false)
         {
             open++;
         }
         double volObj = objrefMesh.Volume();
         double weight = Math.Round(volObj * spezWeight, 3, MidpointRounding.AwayFromZero);
         materials[pos] += weight;
         //matList.Add(matName[pos] + " " + weight + g_ct);
     }
 }
Example #3
0
            private void Select_Map_Click(object sender, EventArgs e)
            {
                //Get the receiver surfaces from the user
                Rhino.DocObjects.ObjRef[] refs;
                Rhino.Input.RhinoGet.GetMultipleObjects("Select Mapping Surfaces", false, Rhino.DocObjects.ObjectType.Brep, out refs);
                List <Brep> B_Temp = new List <Brep>();

                foreach (Rhino.DocObjects.ObjRef o in refs)
                {
                    Rhino.DocObjects.ObjectType t = o.Geometry().ObjectType;

                    if (o.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Brep || o.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Extrusion || o.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Surface)
                    {
                        B_Temp.Add(o.Brep());
                    }
                }

                Rec_Srfs = B_Temp.ToArray();

                if (Rec_Srfs.Length > 0)
                {
                    Select_Map.Text = "Select Mapping Surface: Complete";
                }
                else
                {
                    Select_Map.Text = "Select Mapping Surface";
                }
            }
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);
        }
Example #5
0
 static Rhino.DocObjects.ObjectType SpaceMorphObjectFilter()
 {
     Rhino.DocObjects.ObjectType filter =
         Rhino.DocObjects.ObjectType.Point |
         Rhino.DocObjects.ObjectType.PointSet |
         Rhino.DocObjects.ObjectType.Curve |
         Rhino.DocObjects.ObjectType.Surface |
         Rhino.DocObjects.ObjectType.PolysrfFilter |
         Rhino.DocObjects.ObjectType.Mesh |
         Rhino.DocObjects.ObjectType.Grip |
         Rhino.DocObjects.ObjectType.Cage;
     return(filter);
 }
Example #6
0
        /// <summary>
        /// Rhino calls this function to run the command.
        /// </summary>
        protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            const Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Curve;

            Rhino.DocObjects.ObjRef objref;
            Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select curve to divide", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Curve curve = objref.Curve();
            if (null == curve || curve.IsShort(Rhino.RhinoMath.ZeroTolerance))
            {
                return(Rhino.Commands.Result.Failure);
            }

            int segmentCount = 2;

            rc = Rhino.Input.RhinoGet.GetInteger("Number of segments", false, ref segmentCount, 2, 100);
            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }

            Rhino.Geometry.Point3d[] points;
            curve.DivideByCount(segmentCount, true, out points);
            if (null == points)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // Create a history record
            Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, _historyVersion);
            WriteHistory(history, objref, segmentCount, points.Length);

            for (int i = 0; i < points.Length; i++)
            {
                doc.Objects.AddPoint(points[i], null, history, false);
            }

            doc.Views.Redraw();

            return(Rhino.Commands.Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select surface or polysurface", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.DocObjects.RhinoObject rhobj = objref.Object();
            Rhino.Geometry.Brep          brep  = objref.Brep();
            if (rhobj == null || brep == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            rhobj.Select(false);

            System.Collections.Generic.List <Rhino.Geometry.Curve> curves = new System.Collections.Generic.List <Rhino.Geometry.Curve>();
            foreach (Rhino.Geometry.BrepEdge edge in brep.Edges)
            {
                // Find only the naked edges
                if (edge.Valence == Rhino.Geometry.EdgeAdjacency.Naked)
                {
                    Rhino.Geometry.Curve crv = edge.DuplicateCurve();
                    if (null != crv)
                    {
                        curves.Add(crv);
                    }
                }
            }

            double tol = 2.1 * doc.ModelAbsoluteTolerance;

            Rhino.Geometry.Curve[] output = Rhino.Geometry.Curve.JoinCurves(curves, tol);
            for (int i = 0; i < output.Length; i++)
            {
                Guid id = doc.Objects.AddCurve(output[i]);
                doc.Objects.Select(id);
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
Example #8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface |
                                                               Rhino.DocObjects.ObjectType.PolysrfFilter |
                                                               Rhino.DocObjects.ObjectType.Mesh;
            int integer1 = 300;
            int integer2 = 300;

            Rhino.Input.Custom.OptionInteger optionInteger1 = new Rhino.Input.Custom.OptionInteger(integer1, 200, 900);
            Rhino.Input.Custom.OptionInteger optionInteger2 = new Rhino.Input.Custom.OptionInteger(integer2, 200, 900);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
            go.GeometryFilter = geometryFilter;
            go.AddOptionInteger("Option1", ref optionInteger1);
            go.AddOptionInteger("Option2", ref optionInteger2);
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

            for (; ;)
            {
                var res = go.GetMultiple(1, 0);

                if (res == Rhino.Input.GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    continue;
                }

                else if (res != Rhino.Input.GetResult.Object)
                {
                    return(Result.Cancel);
                }

                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }

                break;
            }

            if (bHavePreselectedObjects)
            {
                // Normally, pre-selected objects will remain selected, when a
                // command finishes, and post-selected objects will be unselected.
                // This this way of picking, it is possible to have a combination
                // of pre-selected and post-selected. So, to make sure everything
                // "looks the same", lets unselect everything before finishing
                // the command.
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                doc.Views.Redraw();
            }

            int objectCount = go.ObjectCount;

            integer1 = optionInteger1.CurrentValue;
            integer2 = optionInteger2.CurrentValue;

            RhinoApp.WriteLine("Select object count = {0}", objectCount);
            RhinoApp.WriteLine("Value of integer1 = {0}", integer1);
            RhinoApp.WriteLine("Value of integer2 = {0}", integer2);

            return(Result.Success);
        }
Example #9
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Hatch;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select hatch to explode", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Hatch hatch = (Rhino.Geometry.Hatch)objref.Geometry();
            if (null == hatch)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.GeometryBase[] hatch_geom = hatch.Explode();
            if (null != hatch_geom)
            {
                for (int i = 0; i < hatch_geom.Length; i++)
                {
                    Rhino.Geometry.GeometryBase geom = hatch_geom[i];
                    if (null != geom)
                    {
                        switch (geom.ObjectType)
                        {
                        case Rhino.DocObjects.ObjectType.Point:
                        {
                            Rhino.Geometry.Point point = (Rhino.Geometry.Point)geom;
                            if (null != point)
                            {
                                doc.Objects.AddPoint(point.Location);
                            }
                        }
                        break;

                        case Rhino.DocObjects.ObjectType.Curve:
                        {
                            Rhino.Geometry.Curve curve = (Rhino.Geometry.Curve)geom;
                            if (null != curve)
                            {
                                doc.Objects.AddCurve(curve);
                            }
                        }
                        break;

                        case Rhino.DocObjects.ObjectType.Brep:
                        {
                            Rhino.Geometry.Brep brep = (Rhino.Geometry.Brep)geom;
                            if (null != brep)
                            {
                                doc.Objects.AddBrep(brep);
                            }
                        }
                        break;
                        }
                    }
                }
            }

            return(Rhino.Commands.Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            bool allBrepSolid = true;
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh;

            GetObject wro = new Rhino.Input.Custom.GetObject();

            wro.SetCommandPrompt("Select objects to weight.");
            wro.GeometryFilter = geometryFilter;

            wro.SubObjectSelect             = true;
            wro.DeselectAllBeforePostSelect = false;
            wro.OneByOnePostSelect          = true;
            wro.GetMultiple(1, 0);

            double volObj3 = 0;


            for (int i = 0; i < wro.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = wro.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                // get selected surface (face)

                Brep refcr = objref.Brep();
                if (refcr != null)
                {
                    var    volObj  = VolumeMassProperties.Compute(refcr);
                    double volObj2 = refcr.GetVolume();
                    volObj3 = volObj3 + volObj2;
                    bool brepSolid = refcr.IsSolid;
                    if (brepSolid == false)
                    {
                        allBrepSolid = false;
                    }
                }
                if (refcr == null)
                {
                    Mesh   refcm   = objref.Mesh();
                    Brep   refmb   = Brep.CreateFromMesh(refcm, false);
                    var    volOb   = VolumeMassProperties.Compute(refmb);
                    double volObj4 = refmb.GetVolume();
                    volObj3 = volObj3 + volObj4;
                    bool brepSolid = refmb.IsSolid;
                    if (brepSolid == false)
                    {
                        allBrepSolid = false;
                    }
                }
            }

            double gold18k   = Math.Round(volObj3 * 0.0158, 2, MidpointRounding.AwayFromZero);
            double gold14k   = Math.Round(volObj3 * 0.0146, 2, MidpointRounding.AwayFromZero);
            double platinum  = Math.Round(volObj3 * 0.0214, 2, MidpointRounding.AwayFromZero);
            double palladium = Math.Round(volObj3 * 0.012, 2, MidpointRounding.AwayFromZero);
            double silver925 = Math.Round(volObj3 * 0.0102, 2, MidpointRounding.AwayFromZero);
            double diaCt     = Math.Round(volObj3 * 0.01755, 2, MidpointRounding.AwayFromZero);

            if (allBrepSolid)
            {
                RhinoApp.WriteLine("The weight is: Gold 18k " + gold18k + "g, Gold 14k " + gold14k + "g, Platinum " + platinum + "g, Palladium " + palladium + "g, Silver 925 " + silver925 + "g, Diamond" + diaCt + "Ct");
            }
            else
            {
                RhinoApp.WriteLine("AT LEAST ONE OBJECT IS OPEN! Result might be false!" + "The weight is: Gold 18k " + gold18k + "g, Gold 14k " + gold14k + "g, Platinum " + platinum + "g, Palladium " + palladium + "g, Silver 925 " + silver925 + "g, Diamond" + diaCt + "Ct");
            }



            return(Result.Success);
        }
Example #11
0
        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);
        }
Example #12
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjRef obj_ref;

            const string prompt = "Select surface or polysurface to mesh";
            const Rhino.DocObjects.ObjectType object_type =
                Rhino.DocObjects.ObjectType.Surface |
                Rhino.DocObjects.ObjectType.Brep;

            Result res = Rhino.Input.RhinoGet.GetOneObject(prompt, false, object_type, out obj_ref);

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

            Rhino.DocObjects.RhinoObject obj = obj_ref.Object();
            if (null == obj)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Mesh obj_mesh = new Rhino.Geometry.Mesh();

            Rhino.Geometry.Mesh[] meshes = obj.GetMeshes(Rhino.Geometry.MeshType.Render);
            if (meshes.Length > 0)
            {
                foreach (Rhino.Geometry.Mesh m in meshes)
                {
                    obj_mesh.Append(m);
                }
            }
            else
            {
                Rhino.Geometry.MeshingParameters mesh_params = obj.GetRenderMeshParameters();
                if (obj.CreateMeshes(Rhino.Geometry.MeshType.Render, mesh_params, false) > 0)
                {
                    meshes = obj.GetMeshes(Rhino.Geometry.MeshType.Render);
                    if (meshes.Length > 0)
                    {
                        foreach (Rhino.Geometry.Mesh m in meshes)
                        {
                            obj_mesh.Append(m);
                        }
                    }
                }
            }

            if (obj_mesh.IsValid)
            {
                obj_mesh.Faces.ConvertQuadsToTriangles();
            }

            if (obj_mesh.IsValid)
            {
                doc.Objects.AddMesh(obj_mesh);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
        private Tuple <Brep[], Dictionary <int, List <Guid> > > GetObjectsToNest()
        {
            //Select Objects To Nest

            const Rhino.DocObjects.ObjectType geometryFilter =
                Rhino.DocObjects.ObjectType.Annotation |
                Rhino.DocObjects.ObjectType.TextDot |
                Rhino.DocObjects.ObjectType.Point |
                Rhino.DocObjects.ObjectType.Curve |
                Rhino.DocObjects.ObjectType.Surface |
                Rhino.DocObjects.ObjectType.PolysrfFilter |
                Rhino.DocObjects.ObjectType.Mesh;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("OpenNest: Select objects for nesting");
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = false;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(true);
            go.EnableUnselectObjectsOnExit(true);
            go.DeselectAllBeforePostSelect = false;


            bool bHavePreselectedObjects = false;

            for (; ;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);

                if (res == Rhino.Input.GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    continue;
                }
                else if (res != Rhino.Input.GetResult.Object)
                {
                    return(null);//Rhino.Commands.Result.Cancel;
                }
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }

                break;
            }

            if (bHavePreselectedObjects)
            {
                // Normally when command finishes, pre-selected objects will remain
                // selected, when and post-selected objects will be unselected.
                // With this sample, it is possible to have a combination of
                // pre-selected and post-selected objects. To make sure everything
                // "looks the same", unselect everything before finishing the command.
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object();

                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                //doc.Views.Redraw();
            }

            List <Guid> guids = new List <Guid>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                guids.Add(go.Object(i).ObjectId);
            }

            Tuple <Brep[], Dictionary <int, List <Guid> > > data = OpenNestLib.OpenNestUtil.SortGuidsByPlanarCurves(guids, this.cp);

            Rhino.RhinoApp.WriteLine("OpenNest: Select object count = {0}", go.ObjectCount);
            this.n = data.Item1.Length;
            Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
            return(data);
        }
Example #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Pick The First Block
            const Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.InstanceReference;

            Rhino.DocObjects.ObjRef         objRef;
            Rhino.DocObjects.InstanceObject primary = null;
            Result r = RhinoGet.GetOneObject("Select a Control Block", false, filter, out objRef);

            if (r == Result.Success)
            {
                primary = objRef.Object() as Rhino.DocObjects.InstanceObject;
            }
            if (primary != null)
            {
                RhinoApp.WriteLine("Primary: " + primary.InstanceDefinition.Name);
            }
            doc.Objects.UnselectAll();
            Rhino.DocObjects.ObjRef         objRef2;
            Rhino.DocObjects.InstanceObject secondary = null;
            Result r2 = RhinoGet.GetOneObject("Select a Secondary Block", false, filter, out objRef2);

            if (r2 == Result.Success)
            {
                secondary = objRef2.Object() as Rhino.DocObjects.InstanceObject;
            }
            if (secondary != null)
            {
                RhinoApp.WriteLine("Secondary: " + secondary.InstanceDefinition.Name);
            }
            doc.Objects.UnselectAll();

            if (primary == null || secondary == null)
            {
                return(Result.Nothing);
            }

            // Now assign the NodeID of the secondary block to the primary.
            string id = secondary.Attributes.GetUserString("NodeID");

            if (string.IsNullOrEmpty(id))
            {
                return(Result.Nothing);
            }

            string constraints = primary.Attributes.GetUserString("Constraints");

            if (string.IsNullOrWhiteSpace(constraints))
            {
                constraints = id;
            }
            else
            {
                constraints += "," + id;
            }


            primary.Attributes.SetUserString("Constraints", constraints);

            return(Result.Success);
        }