protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            RhinoApp.WriteLine("The {0} command is under construction.", EnglishName);
            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gbrep.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);
            RhinoApp.WriteLine("the name of the object is {0}", brep.UserDictionary.GetString("name"));
            return(Result.Success);
        }
示例#2
0
        private void createPlaneBrep()
        {
            Plane plane = new Plane();

            if (type == XYZPlanes.YZ)
            {
                plane = new Plane(origin, new Rhino.Geometry.Vector3d(1, 0, 0));
            }
            else if (type == XYZPlanes.XZ)
            {
                plane = new Plane(origin, new Rhino.Geometry.Vector3d(0, 1, 0));
            }
            else if (type == XYZPlanes.XY)
            {
                plane = new Plane(origin, new Rhino.Geometry.Vector3d(0, 0, 1));
            }

            PlaneSurface plane_surface = new PlaneSurface(plane, new Interval(-size, size), new Interval(-size, size));
            Brep         planeBrep     = Brep.CreateFromSurface(plane_surface);

            if (planeBrep != null)
            {
                Guid guid = UtilOld.addRhinoObjectSceneNode(ref mScene, ref planeBrep, ref mesh_m, "plane" + type.ToString(), out planeSN, true);
                planeObjRef = new Rhino.DocObjects.ObjRef(guid);
            }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.

            GetObject gpath = new GetObject();

            gpath.SetCommandPrompt("get the pathp");
            gpath.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
            gpath.SubObjectSelect = false;
            gpath.Get();
            if (gpath.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gpath.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gpath.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            int path_number = my_obj.Geometry.UserDictionary.Getint("path_number", -1);

            RhinoApp.WriteLine("the number of the object is {0}", path_number);
            return(Result.Success);
        }
示例#4
0
        private bool ReadHistory(Rhino.DocObjects.ReplayHistoryData replay, ref Rhino.DocObjects.ObjRef objref, ref int segmentCount, ref int pointCount)
        {
            if (_historyVersion != replay.HistoryVersion)
            {
                return(false);
            }

            objref = replay.GetRhinoObjRef(0);
            if (null == objref)
            {
                return(false);
            }

            if (!replay.TryGetInt(1, out segmentCount))
            {
                return(false);
            }

            if (!replay.TryGetInt(2, out pointCount))
            {
                return(false);
            }

            return(true);
        }
示例#5
0
        public static Rhino.Geometry.Point3d getRefPoint()
        {
            Guid docBoxID = new Guid(utils.properties.tryGetDocBox());

            Rhino.DocObjects.ObjRef docBox = new Rhino.DocObjects.ObjRef(docBoxID);

            Rhino.Geometry.Curve docBoxCurve = docBox.Curve();

            List <double> xVals = new List <double>();
            List <double> yVals = new List <double>();

            int spanCount = docBoxCurve.SpanCount;

            for (int i = 0; i < spanCount; i++)
            {
                double activeParameter             = docBoxCurve.SpanDomain(i).Min;
                Rhino.Geometry.Point3d activePoint = docBoxCurve.PointAt(activeParameter);

                double activeX = activePoint.X;
                xVals.Add(activeX);

                double activeY = activePoint.Y;
                yVals.Add(activeY);
            }

            xVals.Sort();
            yVals.Sort();

            Rhino.Geometry.Point3d docBoxRefPoint = new Rhino.Geometry.Point3d(xVals[0], yVals[spanCount - 1], 0);

            return(docBoxRefPoint);
        }
示例#6
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);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("CenterPoints");

            if (layerCheck == null)
            {
                doc.Layers.Add("CenterPoints", System.Drawing.Color.Blue);
                layerCheck = doc.Layers.FindName("CenterPoints");
            }

            //pick objects to add center point
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to add center point");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center and add point to doc

            for (int i = 0; i < go.ObjectCount; i++)
            {
                Guid pointG;
                Rhino.DocObjects.ObjRef      objref = go.Object(i);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                var objType = obj.ObjectType;
                if (objType == Rhino.DocObjects.ObjectType.Curve)
                {
                    Curve  curve  = objref.Curve();
                    Circle circle = new Circle();
                    if (!curve.TryGetCircle(out circle, doc.ModelAbsoluteTolerance))
                    {
                        BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                        Point3d     bbObjCenter = bbObj.Center;
                        pointG = doc.Objects.AddPoint(bbObjCenter);
                    }
                    else
                    {
                        Point3d circleCenter = circle.Center;
                        pointG = doc.Objects.AddPoint(circleCenter);
                    }
                }
                else
                {
                    BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                    Point3d     bbObjCenter = bbObj.Center;
                    pointG = doc.Objects.AddPoint(bbObjCenter);
                }
                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(pointG);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
示例#8
0
 /// <summary>
 /// Adds an ObjRef to the list.
 /// </summary>
 /// <param name="objref">An ObjRef to add.</param>
 public void Add(Rhino.DocObjects.ObjRef objref)
 {
     if (null != objref)
     {
         IntPtr pConstObjRef = objref.ConstPointer();
         IntPtr pThis        = NonConstPointer();
         UnsafeNativeMethods.ON_ClassArrayCRhinoObjRef_Append(pThis, pConstObjRef);
     }
 }
示例#9
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("Numbers");

            if (layerCheck == null)
            {
                doc.Layers.Add("Numbers", System.Drawing.Color.DarkRed);
                layerCheck = doc.Layers.FindName("Numbers");
            }

            //pick objects to add center point
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to number");
            var heightref = new Rhino.Input.Custom.OptionDouble(height);

            go.AddOptionDouble("Text_height_mm", ref heightref);
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center and add point to doc

            for (int i = 0; i < go.ObjectCount; i++)
            {
                height = heightref.CurrentValue;
                Rhino.DocObjects.ObjRef objref = go.Object(i);
                Guid        objGuid            = objref.ObjectId;
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;

                int a = i + 1;

                Plane plane = Plane.WorldXY;
                plane.Origin = bbObjCenter;
                var    Justification = TextJustification.MiddleCenter;
                string text          = a.ToString();
                var    Font          = "Arial";

                Guid num = doc.Objects.AddText(text, plane, height, Font, false, false, Justification);

                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(num);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();

                int groupIndex = doc.Groups.Count;
                groupIndex++;
                string group = groupIndex.ToString();
                var    gI    = doc.Groups.Add(group);
                doc.Groups.AddToGroup(gI, num);
                doc.Groups.AddToGroup(gI, objGuid);
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
示例#10
0
        //Update illustrator doc bound if docbox changes in rhino.
        public static void docBoxChanges(Rhino.DocObjects.RhinoObject docBox)
        {
            //Parse rectangle from incoming RhinoObject.
            Guid incomingGuid = docBox.Id;

            Rhino.Geometry.Curve newCurve = null;

            Rhino.DocObjects.ObjRef oRef = new Rhino.DocObjects.ObjRef(incomingGuid);

            newCurve = oRef.Curve();

            Rhino.Geometry.BoundingBox newDimsBox = newCurve.GetBoundingBox(false);

            Rhino.Geometry.Point3d newMinPoint = newDimsBox.Min;
            Rhino.Geometry.Point3d newMaxPoint = newDimsBox.Max;

            double newWidth  = newMaxPoint.X - newMinPoint.X;
            double newHeight = newMaxPoint.Y - newMinPoint.Y;

            int conversion = utils.units.conversion();

            //Compare previous size, or record if first run.
            string D01_Path = utils.file_structure.getPathFor("D01");
            string jsxPath  = utils.file_structure.getJavascriptPath();

            if (System.IO.File.Exists(D01_Path) == false)
            {
                string newData = newWidth.ToString() + "|" + newHeight.ToString();
                System.IO.File.WriteAllText(D01_Path, newData);
            }
            else if (System.IO.File.Exists(D01_Path) == true)
            {
                //If file exists, verify bounds changed. (Otherwise, box moved.)
                string[] oldData   = System.IO.File.ReadAllText(D01_Path).Split('|');
                double   oldWidth  = Convert.ToDouble(oldData[0]);
                double   oldHeight = Convert.ToDouble(oldData[1]);

                //utils.debug.ping(0, "Width change: " + newWidth.ToString() + " - " + oldWidth.ToString());

                if (oldWidth == newWidth && oldHeight == newHeight)
                {
                    //outbound.push.fullReset();
                }
                else
                {
                    string newData = newWidth.ToString() + "|" + newHeight.ToString();
                    System.IO.File.WriteAllText(D01_Path, newData);

                    echo.interop echo = new echo.interop();
                    echo.docBounds(newWidth, newHeight, conversion, jsxPath);

                    //outbound.push.fullReset();
                }
            }
        }
示例#11
0
    public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject();
        go0.SetCommandPrompt("Source curve");
        go0.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go0.SubObjectSelect = false;
        go0.EnablePreSelect(false, true);
        go0.DeselectAllBeforePostSelect = false;
        go0.Get();
        if (go0.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go0.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0);

        Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject();
        go1.SetCommandPrompt("Source curve");
        go1.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
        go1.SubObjectSelect = false;
        go1.EnablePreSelect(false, true);
        go1.DeselectAllBeforePostSelect = false;
        go1.Get();
        if (go1.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go1.CommandResult());
        }

        Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0);

        Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false);

        Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
示例#12
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            RhinoApp.WriteLine("The {0} command is under construction.", EnglishName);

            Rhino.Input.Custom.GetObject gmesh = new Rhino.Input.Custom.GetObject();
            gmesh.SetCommandPrompt("Get the Mesh");
            gmesh.GeometryFilter  = Rhino.DocObjects.ObjectType.Mesh;
            gmesh.SubObjectSelect = true;
            gmesh.Get();
            if (gmesh.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gmesh.CommandResult());
            }
            Rhino.DocObjects.ObjRef      objref = gmesh.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Rhino.Geometry.Mesh mesh = objref.Mesh();
            if (mesh == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            obj.Select(false);

            MeshTextureCoordinateList texture_list = mesh.TextureCoordinates;

            for (int i = 0; i < texture_list.Count - 1; i++)
            {
                Point2f f1 = texture_list[i];
                Point2f f2 = texture_list[i + 1];
                Point3d t1 = new Point3d(f1.X, f1.Y, 0);
                Point3d t2 = new Point3d(f2.X, f2.Y, 0);
                Line    l  = new Line(t1, t2);
                doc.Objects.AddLine(l);
                RhinoApp.WriteLine("Line added");
            }
            doc.Views.Redraw();
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            p.painted_object_        = mesh;
            p.if_painted_object_set_ = true;
            mesh.UserDictionary.Set("name", "myMesh");
            mesh.UserDictionary.Set("isMovable", false);
            p.graph = new DijkstraGraph(10);
            RhinoApp.WriteLine("Mesh Got");
            return(Result.Success);
        }
示例#13
0
        public static string tryGetDocBox()
        {
            string D10_Path = file_structure.getPathFor("D10");

            if (delta_states.getGeoDeltaState() == 3)
            {
                string docBoxGUID = System.IO.File.ReadAllText(D10_Path);

                return(docBoxGUID);
            }
            else
            {
                if (System.IO.File.Exists(D10_Path) == false)
                {
                    string docBoxGUID = makeDocBox();

                    return(docBoxGUID);
                }
                else if (System.IO.File.Exists(D10_Path) == true)
                {
                    //If docBox has already been created, get GUID.
                    string docBoxGUID = System.IO.File.ReadAllText(D10_Path);

                    Guid searchGuid = new Guid(docBoxGUID);

                    Rhino.DocObjects.ObjRef docBox = new Rhino.DocObjects.ObjRef(searchGuid);

                    try
                    {
                        string test = docBox.Curve().ToString();

                        return(docBoxGUID);
                    }
                    catch (Exception e)
                    {
                        string guid = makeDocBox();

                        return(guid);
                    }
                    finally
                    {
                        //?
                    }
                }
            }

            return("error");
        }
        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);
        }
示例#15
0
        private bool WriteHistory(Rhino.DocObjects.HistoryRecord history, Rhino.DocObjects.ObjRef objref, int segmentCount, int pointCount)
        {
            if (!history.SetObjRef(0, objref))
            {
                return(false);
            }

            if (!history.SetInt(1, segmentCount))
            {
                return(false);
            }

            if (!history.SetInt(2, pointCount))
            {
                return(false);
            }

            return(true);
        }
示例#16
0
    public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc)
    {
        ObjectType filter = SpaceMorphObjectFilter();

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

        Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Surface to splop on");
        go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface;
        go.SubObjectSelect = false;
        go.EnablePreSelect(false, true);
        go.DeselectAllBeforePostSelect = false;
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef srfref = go.Object(0);

        double u, v;

        srfref.SurfaceParameter(out u, out v);

        Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u, v);

        Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv);
        Rhino.Geometry.GeometryBase           geom  = objref.Geometry().Duplicate();
        if (morph.Morph(geom))
        {
            doc.Objects.Add(geom);
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
示例#17
0
        public static string tryGetDocBoxLabel()
        {
            string D30_Path = file_structure.getPathFor("D30");

            string docBoxLabelGUID = System.IO.File.ReadAllText(D30_Path);

            Guid searchGuid = new Guid(docBoxLabelGUID);

            Rhino.DocObjects.ObjRef docBox = new Rhino.DocObjects.ObjRef(searchGuid);

            try
            {
                string test = docBox.TextEntity().ToString();

                return(searchGuid.ToString());
            }
            catch (Exception e)
            {
                return("error");
            }
        }
    public static Rhino.Commands.Result LineBetweenCurves(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.DocObjects.ObjRef objRef0 = go.Object(0);
        Rhino.DocObjects.ObjRef objRef1 = go.Object(1);

        double t0 = Rhino.RhinoMath.UnsetValue;
        double t1 = Rhino.RhinoMath.UnsetValue;

        Rhino.Geometry.Curve curve0 = objRef0.CurveParameter(out t0);
        Rhino.Geometry.Curve curve1 = objRef1.CurveParameter(out t1);
        if (null == curve0 || !Rhino.RhinoMath.IsValidDouble(t0) ||
            null == curve1 || !Rhino.RhinoMath.IsValidDouble(t1))
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Line line = Rhino.Geometry.Line.Unset;
        bool rc = Rhino.Geometry.Line.TryCreateBetweenCurves(curve0, curve1, ref t0, ref t1, false, false, out line);

        if (rc)
        {
            if (Guid.Empty != doc.Objects.AddLine(line))
            {
                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }
        return(Rhino.Commands.Result.Failure);
    }
示例#19
0
    public static Rhino.Commands.Result ExtractRenderMesh(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef objRef = null;
        Rhino.Commands.Result   rc     = Rhino.Input.RhinoGet.GetOneObject("Select surface or polysurface", false, Rhino.DocObjects.ObjectType.Brep, out objRef);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

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

        System.Collections.Generic.List <Rhino.DocObjects.RhinoObject> objList = new System.Collections.Generic.List <Rhino.DocObjects.RhinoObject>(1);
        objList.Add(obj);

        Rhino.DocObjects.ObjRef[] meshObjRefs = Rhino.DocObjects.RhinoObject.GetRenderMeshes(objList, true, false);
        if (null != meshObjRefs)
        {
            for (int i = 0; i < meshObjRefs.Length; i++)
            {
                Rhino.DocObjects.ObjRef meshObjRef = meshObjRefs[i];
                if (null != meshObjRef)
                {
                    Rhino.Geometry.Mesh mesh = meshObjRef.Mesh();
                    if (null != mesh)
                    {
                        doc.Objects.AddMesh(mesh);
                    }
                }
            }
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
示例#20
0
        /// <summary>
        /// Rhino calls this function to remake objects when inputs have changed.
        /// </summary>
        protected override bool ReplayHistory(Rhino.DocObjects.ReplayHistoryData replay)
        {
            Rhino.DocObjects.ObjRef objref = null;
            int segmentCount = 0;
            int pointCount   = 0;

            if (!ReadHistory(replay, ref objref, ref segmentCount, ref pointCount))
            {
                return(false);
            }

            Rhino.Geometry.Curve curve = objref.Curve();
            if (null == curve)
            {
                return(false);
            }

            if (pointCount != replay.Results.Length)
            {
                return(false);
            }

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

            for (int i = 0; i < points.Length; i++)
            {
                replay.Results[i].UpdateToPoint(points[i], null);
            }

            return(true);
        }
示例#21
0
    public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
    {
        // Select objects to orient
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to orient");
        go.SubObjectSelect = false;
        go.GroupSelect     = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Point to orient from
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Point to orient from");
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Define source plane
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }
        Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
        source_plane.Origin = gp.Point();

        // Surface to orient on
        Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject();
        gs.SetCommandPrompt("Surface to orient on");
        gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface;
        gs.SubObjectSelect             = true;
        gs.DeselectAllBeforePostSelect = false;
        gs.OneByOnePostSelect          = true;
        gs.Get();
        if (gs.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gs.CommandResult());
        }

        Rhino.DocObjects.ObjRef objref = gs.Object(0);
        // get selected surface object
        Rhino.DocObjects.RhinoObject obj = objref.Object();
        if (obj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // get selected surface (face)
        Rhino.Geometry.Surface surface = objref.Surface();
        if (surface == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // Unselect surface
        obj.Select(false);

        // Point on surface to orient to
        gp.SetCommandPrompt("Point on surface to orient to");
        gp.Constrain(surface, false);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Do transformation
        Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
        double u, v;

        if (surface.ClosestPoint(gp.Point(), out u, out v))
        {
            Rhino.Geometry.Plane target_plane;
            if (surface.FrameAt(u, v, out target_plane))
            {
                // Build transformation
                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);

                // Do the transformation. In this example, we will copy the original objects
                const bool delete_original = false;
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    doc.Objects.Transform(go.Object(i), xform, delete_original);
                }

                doc.Views.Redraw();
                rc = Rhino.Commands.Result.Success;
            }
        }
        return(rc);
    }
示例#22
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            int counter = 0;

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select curves to offset.");
            go.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            go.GroupSelect                 = true;
            go.SubObjectSelect             = true;
            go.DeselectAllBeforePostSelect = true;
            go.OneByOnePostSelect          = false;
            go.GetMultiple(1, 0);


            GetOption gop  = new GetOption();
            var       dist = new Rhino.Input.Custom.OptionDouble(distVal);

            gop.SetCommandPrompt("Set values. Press enter when done.");
            gop.AddOptionDouble("Distance", ref dist);
            int optList = gop.AddOptionList("CornerStyle", corners, cornerIndex);

            gop.AcceptNothing(true);

            while (true)
            {
                if (gop.Get() == GetResult.Nothing)
                {
                    break;
                }

                else if (gop.OptionIndex() == optList)
                {
                    cornerIndex = gop.Option().CurrentListOptionIndex;
                }

                else
                {
                    distVal = dist.CurrentValue;
                }
            }



            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = go.Object(i);
                var curve = objref.Curve();
                if (curve == null)
                {
                    return(Result.Nothing);
                }
                Plane plane;
                if (!curve.TryGetPlane(out plane))
                {
                    curve.DivideByCount(3, true, out Point3d[] curvePoints);
                    plane = new Plane(curvePoints[0], curvePoints[1], curvePoints[2]);
                }

                try
                {
                    var curves = curve.Offset(plane, distVal, doc.ModelAbsoluteTolerance, cornerStyle[cornerIndex]);
                    foreach (var offsetcurve in curves)
                    {
                        doc.Objects.AddCurve(offsetcurve);
                    }
                }
                catch
                {
                    counter++;
                }
            }

            if (counter > 0)
            {
                RhinoApp.WriteLine(counter + " out of " + go.ObjectCount + " offset values were out of scope!");
            }

            doc.Views.Redraw();



            // ---

            return(Result.Success);
        }
示例#23
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double tolerance      = doc.ModelAbsoluteTolerance;
            double angleTolerance = doc.ModelAngleToleranceRadians;


            List <Curve> icur = new List <Curve>();

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

            gcr.SetCommandPrompt("Select reference circles for prongs. (No curves)");
            gcr.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            gcr.GroupSelect                 = true;
            gcr.SubObjectSelect             = true;
            gcr.DeselectAllBeforePostSelect = true;
            gcr.OneByOnePostSelect          = false;
            gcr.GetMultiple(1, 0);

            for (int ie = 0; ie < gcr.ObjectCount; ie++)
            {
                Rhino.DocObjects.ObjRef      objref = gcr.Object(ie);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                Curve refcr = objref.Curve();
                if (refcr == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);

                icur.Add(refcr);
            }

            while (true)
            {
                m_escape_key_pressed       = false;
                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;

                Point3d pt0 = new Point3d(0, 0, hight);
                Point3d pt1 = new Point3d(0, 0, -(length - hight));

                double rotationRadiant = ((rotation / 180) * 3.1415);

                List <Point3d> curvePoints = new List <Point3d>()
                {
                    pt0, pt1
                };
                Curve prongCurve = Curve.CreateInterpolatedCurve(curvePoints, 3);

                if (!capBool)
                {
                    capMode = PipeCapMode.Flat;
                }
                else if (capBool)
                {
                    capMode = PipeCapMode.Round;
                }

                Brep[] cylBrep1 = Brep.CreatePipe(prongCurve, prongDia / 2, false, capMode, false, tolerance, angleTolerance);
                Brep   cylBrep2 = cylBrep1[0];
                cylBrep2.Faces.RemoveAt(2);
                Brep cylBrep3 = cylBrep2.CapPlanarHoles(tolerance);

                if (capBool)
                {
                    Vector3d     scaleVec   = new Vector3d(0, 0, 1);
                    var          scalePlane = new Plane(pt0, scaleVec);
                    var          capScale   = Transform.Scale(scalePlane, 1.0, 1.0, capHight);
                    var          surf2      = cylBrep3.Faces[1].UnderlyingSurface();
                    NurbsSurface nurbSurf2  = surf2.ToNurbsSurface();
                    nurbSurf2.Transform(capScale);
                    Brep capBrep = nurbSurf2.ToBrep();
                    cylBrep3.Append(capBrep);
                    cylBrep3.Faces.RemoveAt(1);
                }

                cylBrep3.Compact();
                cylBrep3.JoinNakedEdges(tolerance);
                string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");
                Brep[] brepArray    = new Brep[1] {
                    cylBrep3
                };
                var prongIndex = doc.InstanceDefinitions.Add("Prong" + instDefCount, "RefProng", Point3d.Origin, brepArray);

                foreach (Curve c in icur)
                {
                    Circle circleProngs = new Circle();
                    c.TryGetCircle(out circleProngs, tolerance);
                    NurbsCurve curveProngs = circleProngs.ToNurbsCurve();

                    Plane    planeNew = circleProngs.Plane;
                    Vector3d plVec    = planeNew.Normal;

                    if (planeNew == null)
                    {
                        curveProngs.DivideByCount(3, true, out Point3d[] curveProngsPoints);
                        planeNew = new Plane(curvePoints[0], curveProngsPoints[1], curveProngsPoints[2]);
                    }


                    Curve[] offsetCurveArray = curveProngs.Offset(planeNew, prongDia / 4, tolerance, CurveOffsetCornerStyle.Sharp);

                    Curve offsetCurve = offsetCurveArray[0];

                    double[] segParameters = offsetCurve.DivideByCount(prongCount, true);

                    List <Point3d> prongPoints = new List <Point3d>();
                    List <Guid>    idsInter    = new List <Guid>();

                    foreach (double p in segParameters)
                    {
                        Point3d zen        = new Point3d(0, 0, 0);
                        Point3d prongPoint = offsetCurve.PointAt(p);

                        Point3d  center  = circleProngs.Center;
                        Vector3d moveV   = new Vector3d(prongPoint);
                        Vector3d zaxis   = new Vector3d(0.0, 0.0, 1.0);
                        Plane    planeOr = new Plane(zen, zaxis);
                        Plane    plane   = new Plane(prongPoint, plVec);

                        var transform1 = Transform.PlaneToPlane(planeOr, plane);
                        var transform2 = Transform.Rotation(rotationRadiant, plVec, center);

                        var prongA = doc.Objects.AddInstanceObject(prongIndex, transform1);
                        var prongB = doc.Objects.Transform(prongA, transform2, true);

                        ids.Add(prongB);
                    }
                    doc.Views.Redraw();
                }


                GetOption go = new Rhino.Input.Custom.GetOption();
                go.SetCommandPrompt("Set prong parameters.");
                go.AcceptNothing(true);

                var countProng  = new Rhino.Input.Custom.OptionInteger(prongCount);
                var diaProng    = new Rhino.Input.Custom.OptionDouble(prongDia);
                var hightProng  = new Rhino.Input.Custom.OptionDouble(hight);
                var lengthProng = new Rhino.Input.Custom.OptionDouble(length);
                var rotProng    = new Rhino.Input.Custom.OptionDouble(rotation);
                var capProng    = new Rhino.Input.Custom.OptionToggle(capBool, "Flat", "Round");
                var hightCap    = new Rhino.Input.Custom.OptionDouble(capHight);

                go.AddOptionInteger("Count", ref countProng);
                go.AddOptionDouble("Diameter", ref diaProng);
                go.AddOptionDouble("Hight", ref hightProng);
                go.AddOptionDouble("Length", ref lengthProng);
                go.AddOptionDouble("Rotation", ref rotProng);
                go.AddOptionToggle("Cap", ref capProng);
                if (capBool)
                {
                    go.AddOptionDouble("Caphight", ref hightCap);
                }

                GetResult res = go.Get();

                if (m_escape_key_pressed)
                {
                    break;
                }

                hight      = hightProng.CurrentValue;
                length     = lengthProng.CurrentValue;
                prongCount = countProng.CurrentValue;
                prongDia   = diaProng.CurrentValue;
                rotation   = rotProng.CurrentValue;
                capBool    = capProng.CurrentValue;
                capHight   = hightCap.CurrentValue;

                if (length <= 0.0)
                {
                    length = 1.0;
                }
                if (prongCount <= 0)
                {
                    prongCount = 1;
                }
                if (prongDia <= 0.0)
                {
                    prongDia = 1.0;
                }
                if (res == GetResult.Nothing)
                {
                    break;
                }

                doc.Objects.Delete(ids, true);
            }
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;

            doc.Groups.Add(ids);

            return(Result.Success);
        }
示例#24
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double       tolerance = doc.ModelAbsoluteTolerance;
            List <Curve> curves    = new List <Curve>();

            //Select surface

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

            gs.SetCommandPrompt("Surface to orient on");
            gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = true;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref_Surface = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj            = objref_Surface.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }
            surface = objref_Surface.Surface();

            if (surface == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);

            //Select Line(s)
            GetObject gl = new GetObject();

            gl.SetCommandPrompt("Select one or two line(s)");
            gl.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gl.DeselectAllBeforePostSelect = true;
            gl.OneByOnePostSelect          = true;
            gl.GetMultiple(1, 0);

            for (int i = 0; i < gl.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref_Line = gl.Object(i);
                curve = objref_Line.Curve();

                Curve curveRe = curve.Rebuild(60, 3, true);
                curves.Add(curveRe);
            }

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

            if (curves.Count > 1)
            {
                Curve curve2 = curves[0];
                Curve curve3 = curves[1];
                if (curve2.IsClosed || curve3.IsClosed)
                {
                    Rhino.UI.Dialogs.ShowMessage("Please only select open curves for two line pave.", "Warning!");
                    return(Result.Failure);
                }

                while (true)
                {
                    cir_guid_list = new List <Guid>();



                    var   tweenCurves = Curve.CreateTweenCurvesWithSampling(curve2, curve3, 1, 30, tolerance);
                    Curve tCurve      = tweenCurves[0];

                    //3 point circle
                    Point3d   po1   = curve2.PointAtStart;
                    Point3d   po2   = curve3.PointAtStart;
                    LineCurve line1 = new LineCurve(po1, po2);
                    double[]  param = line1.DivideByCount(2, false);

                    double param1 = param[0];
                    double param2 = param[0];
                    double param3 = param[0];

                    Curve curve1 = line1;



                    while (true)
                    {
                        Circle outCircle = Circle.TryFitCircleTTT(curve1, curve2, curve3, param1, param2, param3);


                        //circle normal to surface

                        Point3d outCircleCenter = outCircle.Center;
                        double  outCircleRadius = outCircle.Radius;
                        double  u, v;
                        surface.ClosestPoint(outCircleCenter, out u, out v);
                        var     direction  = surface.NormalAt(u, v);
                        Point3d surfCenter = surface.PointAt(u, v);
                        Plane   pl1        = new Plane(surfCenter, direction);
                        Circle  circle     = new Circle(pl1, surfCenter, outCircleRadius - offSetStone);
                        Circle  circleDist = new Circle(pl1, surfCenter, outCircleRadius + stoneDist);
                        Guid    cir_guid   = doc.Objects.AddCircle(circle);
                        cir_guid_list.Add(cir_guid);


                        //Cut tween curve at latest circle center
                        Point3d pointOnCurve;
                        Point3d pointOnCircle;
                        Curve   circleDistCurve = circleDist.ToNurbsCurve();
                        tCurve.Domain = new Interval(0, tCurve.GetLength());
                        Curve[] splitCurves = tCurve.Split(outCircleRadius);
                        if (splitCurves is null)
                        {
                            break;
                        }
                        tCurve = splitCurves[splitCurves.Length - 1];
                        tCurve.ClosestPoints(circleDistCurve, out pointOnCurve, out pointOnCircle);

                        //Cut tween curve at latest circle border
                        double curveSplitParam;
                        tCurve.Domain = new Interval(0, tCurve.GetLength());
                        tCurve.ClosestPoint(pointOnCurve, out curveSplitParam);
                        splitCurves = tCurve.Split(curveSplitParam);
                        if (splitCurves is null)
                        {
                            break;
                        }
                        tCurve = splitCurves[splitCurves.Length - 1];

                        //New parameter at curve1
                        double circleParam;
                        circleDistCurve.ClosestPoint(pointOnCircle, out circleParam);
                        param1 = circleParam;
                        curve1 = circleDistCurve;

                        //New parameter at curves[0]
                        double paramCurve0New;
                        curve2.ClosestPoint(pointOnCircle, out paramCurve0New);
                        Point3d pointCurve0New = curve2.PointAt(paramCurve0New);
                        double  distNewPoints0 = pointOnCircle.DistanceTo(pointCurve0New);
                        param2 = paramCurve0New + distNewPoints0;

                        //New parameter at curves[1]
                        double paramCurve1New;
                        curve3.ClosestPoint(pointOnCircle, out paramCurve1New);
                        Point3d pointCurve1New = curve3.PointAt(paramCurve1New);
                        double  distNewPoints1 = pointOnCircle.DistanceTo(pointCurve1New);
                        param3 = paramCurve1New + distNewPoints1;
                    }

                    doc.Views.Redraw();


                    //Options
                    var go = new GetOption();
                    go.SetCommandPrompt("Set options.");


                    var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                    var distStone  = new Rhino.Input.Custom.OptionDouble(stoneDist);
                    var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");


                    go.AddOptionDouble("Offset", ref stoneOff);
                    go.AddOptionDouble("Distance", ref distStone);
                    go.AddOptionToggle("Reverse", ref boolOption);

                    go.AcceptNothing(true);

                    var res = go.Get();

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

                    foreach (var gui in cir_guid_list)
                    {
                        var gu = doc.Objects.Find(gui);
                        doc.Objects.Delete(gu);
                    }



                    offSetStone = stoneOff.CurrentValue;
                    stoneDist   = distStone.CurrentValue;
                    optionBool  = boolOption.CurrentValue;

                    if (optionBool == true)
                    {
                        curve2.Reverse();
                        curve2 = curve2.Rebuild(60, 3, false);
                        curve3.Reverse();
                        curve3     = curve3.Rebuild(60, 3, false);
                        optionBool = false;
                    }
                }
            }

            else
            {
                while (true)
                {
                    cir_guid_list = new List <Guid>();
                    List <Point3d> points = new List <Point3d>();


                    double length     = (diamStone / 2) + offSetStone;
                    double crv_length = curve.GetLength();

                    Point3d point = curve.PointAtLength(length);
                    points.Add(point);

                    while (true)
                    {
                        length += diamStone + offSetStone;
                        if (length > crv_length)
                        {
                            break;
                        }
                        point = curve.PointAtLength(length);
                        points.Add(point);
                    }

                    foreach (var poi in points)
                    {
                        double u, v;
                        surface.ClosestPoint(poi, out u, out v);
                        var      direction = surface.NormalAt(u, v);
                        double   x         = direction.X;
                        double   y         = direction.Y;
                        double   z         = direction.Z;
                        Vector3d vt1       = new Vector3d(x, y, z);
                        Plane    pl1       = new Plane(poi, vt1);
                        Circle   circle    = new Circle(pl1, poi, diamStone / 2);
                        Guid     cir_guid  = doc.Objects.AddCircle(circle);
                        cir_guid_list.Add(cir_guid);
                    }

                    doc.Views.Redraw();

                    //Options
                    var go = new GetOption();
                    go.SetCommandPrompt("Set options.");

                    var stoneDiam  = new Rhino.Input.Custom.OptionDouble(diamStone);
                    var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                    var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");

                    go.AddOptionDouble("StoneDiam", ref stoneDiam);
                    go.AddOptionDouble("Offset", ref stoneOff);
                    go.AddOptionToggle("Reverse", ref boolOption);

                    go.AcceptNothing(true);

                    var res = go.Get();

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

                    foreach (var gui in cir_guid_list)
                    {
                        var gu = doc.Objects.Find(gui);
                        doc.Objects.Delete(gu);
                    }


                    diamStone   = stoneDiam.CurrentValue;
                    offSetStone = stoneOff.CurrentValue;
                    optionBool  = boolOption.CurrentValue;

                    if (optionBool == true)
                    {
                        curve.Reverse();
                    }
                }
            }


            doc.Views.Redraw();

            doc.Groups.Add(cir_guid_list);

            return(Result.Success);
        }
示例#25
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);
        }
示例#27
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);
     }
 }
示例#28
0
 /// <summary>
 /// Call this function to see if the point was on an object. If the point was
 /// on an object an ObjRef is returned; otherwise null is returned.
 /// </summary>
 /// <returns>A point object reference.</returns>
 public Rhino.DocObjects.ObjRef PointOnObject()
 {
   Rhino.DocObjects.ObjRef rc = new Rhino.DocObjects.ObjRef();
   IntPtr pThis = ConstPointer();
   IntPtr pObjRef = rc.NonConstPointer();
   if (!UnsafeNativeMethods.CRhinoGetPoint_PointOnObject(pThis, pObjRef))
   {
     rc.Dispose();
     rc = null;
   }
   return rc;
 }
示例#29
0
        public static void curves(int state, Rhino.DocObjects.RhinoObject geo)
        {
            //Verify geometery is being added, not transformed.
            string G00_Path    = utils.file_structure.getPathFor("G00");
            int    verifyState = Convert.ToInt32(System.IO.File.ReadAllText(G00_Path));

            if (verifyState == 3)
            {
                state = 3;
            }
            else
            {
                System.IO.File.WriteAllText(G00_Path, state.ToString());
            }

            //Grab reference point from docBox.
            Rhino.Geometry.Point3d refPoint = utils.properties.getRefPoint();
            double refPointX = refPoint.X;
            double refPointY = refPoint.Y;

            //Determine and sanitize cache file for new geometry.
            string G10_Path = utils.file_structure.getPathFor("G10");

            if (System.IO.File.Exists(G10_Path) == false)
            {
                System.IO.File.WriteAllText(G10_Path, "");
                //System.Threading.Thread.Sleep(500);
            }

            //Parse curve geometry from RhinoObject.
            Guid incomingGuid = geo.Id;

            Rhino.Geometry.Curve newCurve = null;

            int layerIndex = geo.Attributes.LayerIndex;

            Rhino.DocObjects.Layer incomingLayer = Rhino.RhinoDoc.ActiveDoc.Layers[layerIndex];
            string incomingLayerName             = incomingLayer.Name;

            Rhino.DocObjects.ObjRef oRef = new Rhino.DocObjects.ObjRef(incomingGuid);

            //Verify object is a curve, otherwise quit.
            if (oRef.Geometry().ObjectType.ToString().ToLower().Contains("curve"))
            {
                newCurve = oRef.Curve();
            }
            else
            {
                //System.IO.File.AppendAllText(G10_Path, "X|" + Environment.NewLine);
                return;
            }

            //Run curve geometry through the coin sorter.
            //All data is cached in the same file, but keyed at the beginning by type.
            //0 - linear curve
            //1 - linear polyline
            //2 - arc
            //3 - circle
            //4 - ellipse
            //5 - arbitrary curve
            //6 - complex polycurve

            //New type key:
            //0 - linear curve
            //1 - linear polyline
            //2 - any non-linear curve
            if (newCurve.Degree == 1)
            {
                if (newCurve.SpanCount == 1)
                {
                    //Treat as linear curve.
                    //utils.debug.ping(0, "Linear curve added!");

                    Rhino.Geometry.Point3d startPoint = newCurve.PointAtStart;
                    Rhino.Geometry.Point3d endPoint   = newCurve.PointAtEnd;

                    string x1 = (startPoint.X - refPointX).ToString();
                    string y1 = (startPoint.Y - refPointY).ToString();
                    string x2 = (endPoint.X - refPointX).ToString();
                    string y2 = (endPoint.Y - refPointY).ToString();

                    //utils.debug.alert(G10_Path);
                    //utils.debug.alert(incomingGuid.ToString());
                    //utils.debug.alert(incomingLayerName);

                    try
                    {
                        System.IO.File.AppendAllText(G10_Path, "0|" + incomingGuid.ToString() + "|" + incomingLayerName + "|1|" + x1 + "," + y1 + "," + x2 + "," + y2 + Environment.NewLine);
                    }
                    catch (Exception e)
                    {
                        utils.debug.alert(e.ToString());
                    }

                    //utils.debug.alert("Pausing!!");
                }
                else if (newCurve.SpanCount > 1)
                {
                    //Treat as linear polyline.
                    //utils.debug.ping(0, "Linear polyline added!");

                    List <string> coords = new List <string>();

                    int spanCount = newCurve.SpanCount;
                    for (int i = 0; i < spanCount; i++)
                    {
                        double activeParameter             = newCurve.SpanDomain(i).Min;
                        Rhino.Geometry.Point3d activePoint = newCurve.PointAt(activeParameter);

                        double activeX = activePoint.X - refPointX;
                        coords.Add(activeX.ToString());

                        double activeY = activePoint.Y - refPointY;
                        coords.Add(activeY.ToString());

                        if (i == spanCount - 1)
                        {
                            //On reaching final span, also record endpoint.
                            double finalParameter             = newCurve.SpanDomain(i).Max;
                            Rhino.Geometry.Point3d finalPoint = newCurve.PointAt(finalParameter);

                            double finalX = finalPoint.X - refPointX;
                            coords.Add(finalX.ToString());

                            double finalY = finalPoint.Y - refPointY;
                            coords.Add(finalY.ToString());
                        }
                    }

                    string coordInfo = string.Join(",", coords);

                    System.IO.File.AppendAllText(G10_Path, "1|" + incomingGuid.ToString() + "|" + incomingLayerName + "|" + newCurve.SpanCount.ToString() + "|" + coordInfo + Environment.NewLine);
                }
            }
            else if (newCurve.Degree > 1)
            {
                //Generate degree 3 approximation of incoming curve. (Low tolerance makes it more than "good enough")
                Rhino.Geometry.BezierCurve[] bCurveSpans = Rhino.Geometry.BezierCurve.CreateCubicBeziers(newCurve, 0.01, 0.01);
                int bCurveCount = bCurveSpans.Length;

                List <string> bPointData  = new List <string>();
                List <double> bPointCache = new List <double>();

                //Cache point info.
                for (int i = 0; i < bCurveCount; i++)
                {
                    //Starting point caching process.
                    if (i == 0)
                    {
                        //Parse anchor point data.
                        Rhino.Geometry.Point3d activeAnchor = bCurveSpans[i].GetControlVertex3d(0);
                        double activeAnchorX = activeAnchor.X - refPointX;
                        double activeAnchorY = activeAnchor.Y - refPointY;
                        bPointCache.Add(activeAnchorX);
                        bPointCache.Add(activeAnchorY);

                        //Parse left direction data. For starting point, this is the same as the anchor.
                        bPointCache.Add(activeAnchorX);
                        bPointCache.Add(activeAnchorY);

                        //Parse right direction data.
                        Rhino.Geometry.Point3d activeRightDirection = bCurveSpans[i].GetControlVertex3d(1);
                        double activeRightDirectionX = activeRightDirection.X - refPointX;
                        double activeRightDirectionY = activeRightDirection.Y - refPointY;
                        bPointCache.Add(activeRightDirectionX);
                        bPointCache.Add(activeRightDirectionY);

                        //Push packaged point data to final list.
                        string bPoint = string.Join(":", bPointCache);
                        bPointData.Add(bPoint);
                        bPointCache.Clear();
                    }
                    //Intermediate point caching process.
                    else
                    {
                        //Parse anchor point data.
                        Rhino.Geometry.Point3d activeAnchor = bCurveSpans[i].GetControlVertex3d(0);
                        double activeAnchorX = activeAnchor.X - refPointX;
                        double activeAnchorY = activeAnchor.Y - refPointY;
                        bPointCache.Add(activeAnchorX);
                        bPointCache.Add(activeAnchorY);

                        //Parse left direction data.
                        Rhino.Geometry.Point3d activeLeftDirection = bCurveSpans[i - 1].GetControlVertex3d(2);
                        double activeLeftDirectionX = activeLeftDirection.X - refPointX;
                        double activeLeftDirectionY = activeLeftDirection.Y - refPointY;
                        bPointCache.Add(activeLeftDirectionX);
                        bPointCache.Add(activeLeftDirectionY);

                        //Parse right direction data.
                        Rhino.Geometry.Point3d activeRightDirection = bCurveSpans[i].GetControlVertex3d(1);
                        double activeRightDirectionX = activeRightDirection.X - refPointX;
                        double activeRightDirectionY = activeRightDirection.Y - refPointY;
                        bPointCache.Add(activeRightDirectionX);
                        bPointCache.Add(activeRightDirectionY);

                        //Push packaged point data to final list.
                        string bPoint = string.Join(":", bPointCache);
                        bPointData.Add(bPoint);
                        bPointCache.Clear();
                    }
                }

                //Cache endpoint info after loop finishes.
                //Parse anchor point data.
                Rhino.Geometry.Point3d lastActiveAnchor = bCurveSpans[bCurveCount - 1].GetControlVertex3d(3);
                double lastActiveAnchorX = lastActiveAnchor.X - refPointX;
                double lastActiveAnchorY = lastActiveAnchor.Y - refPointY;
                bPointCache.Add(lastActiveAnchorX);
                bPointCache.Add(lastActiveAnchorY);

                //Parse left direction data.
                Rhino.Geometry.Point3d lastActiveLeftDirection = bCurveSpans[bCurveCount - 1].GetControlVertex3d(2);
                double lastActiveLeftDirectionX = lastActiveLeftDirection.X - refPointX;
                double lastActiveLeftDirectionY = lastActiveLeftDirection.Y - refPointY;
                bPointCache.Add(lastActiveLeftDirectionX);
                bPointCache.Add(lastActiveLeftDirectionY);

                //Parse right direction data. For the ending point, this is the same as the anchor.
                bPointCache.Add(lastActiveAnchorX);
                bPointCache.Add(lastActiveAnchorY);

                //Push packaged point data to final list.
                string lastBPoint = string.Join(":", bPointCache);
                bPointData.Add(lastBPoint);
                bPointCache.Clear();

                //Finalize and record data.
                string coordInfo = string.Join(";", bPointData);

                System.IO.File.AppendAllText(G10_Path, "2|" + incomingGuid.ToString() + "|" + incomingLayerName + "|" + newCurve.SpanCount.ToString() + "|" + coordInfo + Environment.NewLine);
            }
        }
示例#30
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);
        }
示例#31
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            String[] matName = new String[] { "WhiteGold_18ct", "YellowGold_18ct", "RedGold_18ct", "RodiumBlack_18ct", "Silver_925", "Platinum_960", "Ruby", "Emerald", "Saphir", "Paraiba", "Granat", "Amethyst", "Morganite", "Diamond" };

            Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings();
            settings.VisibleFilter = true;
            System.Collections.Generic.List <Guid> ids = new System.Collections.Generic.List <Guid>();

            List <string> allItems           = new List <string>();
            List <string> metalItems         = new List <string>();
            List <string> stoneItems         = new List <string>();
            List <double> circleStones       = new List <double>();
            List <int>    quantCirclesStones = new List <int>();


            foreach (Rhino.DocObjects.RhinoObject rhObj in doc.Objects.GetObjectList(settings))
            {
                var  objType = rhObj.ObjectType;
                Guid objGuid = rhObj.Id;
                Rhino.DocObjects.ObjRef objref = new Rhino.DocObjects.ObjRef(objGuid);

                if (objType == Rhino.DocObjects.ObjectType.Curve)
                {
                    Curve  curveRadius  = objref.Curve();
                    Circle circleRadius = new Circle();
                    var    circlefound  = curveRadius.TryGetCircle(out circleRadius, doc.ModelAbsoluteTolerance);
                    if (circlefound)
                    {
                        double diamStone = Math.Round(circleRadius.Diameter, 2, MidpointRounding.AwayFromZero);

                        int match = circleStones.IndexOf(diamStone);

                        if (match == -1)
                        {
                            circleStones.Add(diamStone);
                            quantCirclesStones.Add(1);
                        }
                        else
                        {
                            int currVal = quantCirclesStones[match];
                            quantCirclesStones[match] = currVal + 1;
                        }
                    }
                }

                Rhino.DocObjects.Material mat = rhObj.GetMaterial(true);
                var objMatName = mat.Name;
                int pos        = Array.IndexOf(matName, objMatName);
                if (pos == -1)
                {
                    continue;
                }
                switch (pos)
                {
                //18ctGold
                case int n when(n < 4):
                    double gold18ct = 0.016;

                    CalMat(doc, gold18ct, objType, objref, metalItems, matName, pos, " g");
                    break;

                //Silver
                case 4:
                    double silver = 0.0105;
                    CalMat(doc, silver, objType, objref, metalItems, matName, pos, " g");
                    break;

                //Platinum
                case 5:
                    double platinum = 0.0203;
                    CalMat(doc, platinum, objType, objref, metalItems, matName, pos, " g");
                    break;

                //ColorStones ruby=4g Emerald=2.65g saphr=4g Paraiba=3g Granat=3.9g Amethyst=2.65 Morganite=2.65
                case 6:
                    double ruby = 0.02;
                    CalMat(doc, ruby, objType, objref, stoneItems, matName, pos, " ct");
                    break;

                case 7:
                    double emerald = 0.0133;
                    CalMat(doc, emerald, objType, objref, stoneItems, matName, pos, " ct");
                    break;

                case 8:
                    double saphir = 0.02;
                    CalMat(doc, saphir, objType, objref, stoneItems, matName, pos, " ct");
                    break;

                case 9:
                    double paraiba = 0.015;
                    CalMat(doc, paraiba, objType, objref, stoneItems, matName, pos, " ct");
                    break;

                case 10:
                    double granat = 0.0195;
                    CalMat(doc, granat, objType, objref, stoneItems, matName, pos, " ct");
                    break;

                case 11:
                    double amethyst = 0.0133;
                    CalMat(doc, amethyst, objType, objref, stoneItems, matName, pos, " ct");
                    break;

                case 12:
                    double morganite = 0.0133;
                    CalMat(doc, morganite, objType, objref, stoneItems, matName, pos, " ct");
                    break;

                //Diamond
                case 13:
                    double diamond = 0.02;
                    CalMat(doc, diamond, objType, objref, stoneItems, matName, pos, " ct");
                    break;
                }
            }

            metalItems.Sort();
            stoneItems.Sort();


            allItems.Add("------Metals(g)/Stones(ct) from solids-------");

            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i] == 0)
                {
                    continue;
                }
                allItems.Add(matName[i] + ": " + materials[i]);
            }

            /*
             * allItems.Add("--------------Metals--------------");
             * for (int i = 0; i < metalItems.Count; i++)
             * {
             *  allItems.Add(metalItems[i]);
             * }
             *
             * allItems.Add("--------------Stone---------------");
             * for (int i = 0; i < stoneItems.Count; i++)
             * {
             *  allItems.Add(stoneItems[i]);
             * }
             */
            allItems.Add("-----------------------------------------------");
            allItems.Add("");
            allItems.Add("-----------Brillants from circles------------");

            double totalCt = 0.0;

            for (int i = 0; i < circleStones.Count; i++)
            {
                double ct;
                ct = Math.Round((circleStones[i] * circleStones[i] * circleStones[i] * 0.6 * 0.0061), 4, MidpointRounding.AwayFromZero);
                allItems.Add("Brill: " + quantCirclesStones[i] + " x " + circleStones[i] + " mm " + ct + " ct Total: " + ct * quantCirclesStones[i] + " ct");
                totalCt = totalCt + ct * quantCirclesStones[i];
            }

            allItems.Add("Total brillant weight: " + totalCt + " ct");
            allItems.Add("-----------------------------------------------");

            String clipboardString = "";

            foreach (String o in allItems)
            {
                clipboardString = clipboardString + o + "\n";
            }

            Clipboard.SetText(clipboardString);

            if (open > 0)
            {
                Dialogs.ShowMessage("At least one object is not closed. Weights might be false.", "Warning!");
            }

            Dialogs.ShowListBox("Report", "This data is copied to your clipboard \n Use Ctrl+V to paste", allItems);

            materials = new double[14];
            open      = 0;

            return(Result.Success);
        }