Beispiel #1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            bool bHavePreselectedObjects = false;

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

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

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

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

                break;
            }


            BoundingBox box = BoundingBox.Empty;

            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();
                if (null != rhinoObject)
                {
                    box.Union(rhinoObject.Geometry.GetBoundingBox(true));
                }
                rhinoObject.Select(false);
            }

            if (box.IsValid)
            {
                RFContext.ClippingBox = new Box(box);
                //RFContext.Clip = true;

                return(Result.Success);
            }

            return(Result.Nothing);
        }
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometryFilter = ObjectType.Mesh;

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select meshes to compute contacts");
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            GetResult res = go.GetMultiple(1, 0);

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

            Rhino.RhinoApp.WriteLine(res.GetType().ToString())

            return(Result.Success);
        }
Beispiel #3
0
        public static GetObject GetRhinoObjects(string prompt, ObjectType geometryFilter)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt(prompt);
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = false;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = true;

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

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

                else if (res != GetResult.Object)
                {
                    return(go);
                }

                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++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
            }

            return(go);
        }
Beispiel #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType selFilter      = ObjectType.PolysrfFilter | ObjectType.Extrusion;
            bool             value          = false;
            double           preShrinkValue = ZERO_CM;

            OptionToggle shrinkToDimensions = new OptionToggle(value, "Off", "On");
            OptionDouble preShrink          = new OptionDouble(preShrinkValue, 0.0, 1.0);
            ObjRef       boxObjRef          = null;

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select the box to net-ify");
            go.AddOptionToggle("Constrain", ref shrinkToDimensions);
            go.AddOptionDouble("PreShrink", ref preShrink, "Preshrink");
            go.GeometryFilter = selFilter;

            go.EnableClearObjectsOnEntry(true);
            go.EnableUnselectObjectsOnExit(true);

            // TODO: clean up this hot mess
            for (;;)
            {
                GetResult getObjResult = go.Get();
                if (getObjResult == GetResult.Object)
                {
                    boxObjRef = go.Object(0);
                    boxObjRef.Object().Select(on: true, syncHighlight: true);
                    go.EnablePreSelect(false, true);
                    go.AcceptNothing(true);
                    continue;
                }

                else if (getObjResult == GetResult.Cancel)
                {
                    return(Result.Cancel);
                }

                // Case where user presses enter
                else if (getObjResult == GetResult.Nothing)
                {
                    if (boxObjRef != null)
                    {
                        preShrinkValue = preShrink.CurrentValue;
                        if (preShrinkValue != ZERO_CM)
                        {
                            boxObjRef = shrinkBoxObj(boxObjRef, preShrinkValue);
                        }
                        drawNetFromObjRef(boxObjRef, doc, shrinkToDimensions.CurrentValue);
                        return(Result.Success);
                    }
                }
            }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected dot
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Annotation;

            go.SetCommandPrompt("Select Text to replace:");
            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount);

            List <TextEntity>  textEntityList  = new List <TextEntity>();
            List <RhinoObject> rhinoObjectList = new List <RhinoObject>();

            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();

                if (rhinoObject.ObjectType == ObjectType.Annotation)
                {
                    TextEntity textEntity = rhinoObject.Geometry as TextEntity;

                    if (textEntity != null)
                    {
                        rhinoObjectList.Add(rhinoObject);
                    }
                }
            }

            FindAndReplaceForm findForm = new FindAndReplaceForm(rhinoObjectList);

            findForm.ShowDialog(RhinoApp.MainWindow());

            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected curve
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;

            GetResult result = go.Get();

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            if (go.ObjectCount != 1)
            {
                RhinoApp.WriteLine("Error: {0} curve is selected.", go.ObjectCount);
                return(Rhino.Commands.Result.Failure);
            }

            RhinoApp.WriteLine("{0} curve is selected.", go.ObjectCount);

            Curve curve = go.Object(0).Curve();

            // If curve is null
            if (curve == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // If curve is Closed Curve Orientation
            if (curve.IsClosed == false)
            {
                RhinoApp.WriteLine("The curve is open");
                return(Rhino.Commands.Result.Failure);
            }
            RhinoUtilities.SetActiveLayer(Properties.Settings.Default.PerforationLayerName, System.Drawing.Color.Green);
            PerforationForm perforationForm = new PerforationForm(curve);

            perforationForm.ShowDialog(RhinoApp.MainWindow());
            RhinoDoc.ActiveDoc.Views.Redraw();
            return(Result.Success);
        }
Beispiel #7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var have_preselected_objects = false;

            var go = new GetObject();

            go.SetCommandPrompt("Select objects");
            go.GeometryFilter  = ObjectType.AnyObject;
            go.GroupSelect     = true;
            go.SubObjectSelect = false;

            while (true)
            {
                go.GetMultiple(1, 0);

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

                if (go.ObjectsWerePreselected)
                {
                    have_preselected_objects = true;
                    go.EnablePreSelect(false, true);
                    go.AlreadySelectedObjectSelect = true;
                    go.EnableClearObjectsOnEntry(false);
                    go.DeselectAllBeforePostSelect = false;
                    go.EnableUnselectObjectsOnExit(false);
                    continue;
                }

                break;
            }

            if (have_preselected_objects)
            {
                for (var i = 0; i < go.ObjectCount; i++)
                {
                    var obj = go.Object(i).Object();
                    obj?.Select(false);
                }

                doc.Views.Redraw();
            }

            RhinoApp.WriteLine("Select object count: {0}", go.ObjectCount);

            return(Result.Success);
        }
Beispiel #8
0
            protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            {
                GetObject getObjs = new GetObject();

                getObjs.SetCommandPrompt("Select objects for schema removal");
                getObjs.GroupSelect     = true;
                getObjs.SubObjectSelect = false;
                getObjs.EnableClearObjectsOnEntry(false);
                getObjs.EnableUnselectObjectsOnExit(false);
                getObjs.DeselectAllBeforePostSelect = false;

                bool hasPreselected = false;

                for (; ;)
                {
                    GetResult res = getObjs.GetMultiple(1, 0);

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

                    if (getObjs.ObjectsWerePreselected)
                    {
                        hasPreselected = true;
                        getObjs.EnablePreSelect(false, true);
                        continue;
                    }
                    break;
                }

                //This chunk just makes sure objects selected during the command stay selected afterwards. Optional.
                if (hasPreselected)
                {
                    SelectAllCommandObjs(getObjs, doc);
                }

                List <RhinoObject> objs = getObjs.Objects().Select(o => o.Object()).ToList();

                foreach (RhinoObject obj in objs)
                {
                    obj.Attributes.DeleteUserString(SpeckleSchemaKey);
                }
                return(Result.Success);
            }
Beispiel #9
0
        private static List <RhinoObject> GetObjectSelection(ObjectType filter = ObjectType.AnyObject)
        {
            // Construct an objects getter
            var getObj = new GetObject();

            getObj.SetCommandPrompt("Select geometry");
            getObj.GroupSelect     = true;
            getObj.SubObjectSelect = false;
            getObj.EnableClearObjectsOnEntry(false);
            getObj.EnableUnselectObjectsOnExit(false);
            getObj.DeselectAllBeforePostSelect = false;
            getObj.GeometryFilter = filter;

            // Get objects
            for (; ;)
            {
                GetResult res = getObj.GetMultiple(1, 0);
                if (res == GetResult.Option)
                {
                    getObj.EnablePreSelect(false, true);
                    continue;
                }
                else if (res != GetResult.Object)
                {
                    return(null);
                }
                if (getObj.ObjectsWerePreselected)
                {
                    getObj.EnablePreSelect(false, true);
                    continue;
                }
                break;
            }

            return(getObj.Objects().Select(o => o.Object()).ToList());
        }
Beispiel #10
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            bool bHavePreselectedObjects = false;

            const ObjectType geometryFilter = ObjectType.MeshFace;

            OptionDouble  minEdgeLengthOption     = new OptionDouble(minEdgeLength, 0.001, 200);
            OptionDouble  maxEdgeLengthOption     = new OptionDouble(maxEdgeLength, 0.001, 200);
            OptionDouble  constriantAngleOption   = new OptionDouble(constriantAngle, 0.001, 360);
            OptionInteger smoothStepsOptions      = new OptionInteger(smoothSteps, 0, 100);
            OptionDouble  smoothSpeedOption       = new OptionDouble(smoothSpeed, 0.01, 1.0);
            OptionDouble  projectAmountOption     = new OptionDouble(projectedAmount, 0.01, 1.0);
            OptionDouble  projectedDistanceOption = new OptionDouble(projectedDistance, 0.01, 100000.0);

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select mesh faces to project onto another mesh");
            go.GeometryFilter = geometryFilter;

            go.AddOptionDouble("ConstraintAngle", ref constriantAngleOption);
            go.AddOptionDouble("MinEdge", ref minEdgeLengthOption);
            go.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption);
            go.AddOptionInteger("SmoothSteps", ref smoothStepsOptions);
            go.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption);

            go.GroupSelect     = true;
            go.SubObjectSelect = true;

            for (; ;)
            {
                GetResult faceres = go.GetMultiple(1, 0);

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

                else if (go.CommandResult() != Result.Success)
                {
                    return(go.CommandResult());
                }

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

                break;
            }

            minEdgeLength   = minEdgeLengthOption.CurrentValue;
            maxEdgeLength   = maxEdgeLengthOption.CurrentValue;
            constriantAngle = constriantAngleOption.CurrentValue;
            smoothSteps     = smoothStepsOptions.CurrentValue;
            smoothSpeed     = smoothSpeedOption.CurrentValue;

            //System.Collections.Generic.List<System.Guid> meshes = new System.Collections.Generic.List<System.Guid>();

            System.Guid rhinoMesh = System.Guid.Empty;

            System.Collections.Generic.List <int> removeFaces = new System.Collections.Generic.List <int>();

            g3.DMesh3 projectFaces = new g3.DMesh3(true, false, false, false);

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

            for (int i = 0; i < go.ObjectCount; i++)
            {
                ObjRef obj = go.Object(i);

                if (rhinoMesh == System.Guid.Empty)
                {
                    rhinoMesh      = obj.ObjectId;
                    rhinoInputMesh = obj.Mesh();

                    for (int j = 0; j < rhinoInputMesh.Vertices.Count; j++)
                    {
                        var vertex = new g3.NewVertexInfo();
                        vertex.n = new g3.Vector3f(rhinoInputMesh.Normals[j].X, rhinoInputMesh.Normals[j].Y, rhinoInputMesh.Normals[j].Z);
                        vertex.v = new g3.Vector3d(rhinoInputMesh.Vertices[j].X, rhinoInputMesh.Vertices[j].Y, rhinoInputMesh.Vertices[j].Z);
                        projectFaces.AppendVertex(vertex);
                    }
                }

                var m = rhinoInputMesh;

                if (rhinoMesh != obj.ObjectId)
                {
                    continue;
                }

                removeFaces.Add(obj.GeometryComponentIndex.Index);

                var mf = rhinoInputMesh.Faces[obj.GeometryComponentIndex.Index];


                if (mf.IsQuad)
                {
                    double dist1 = m.Vertices[mf.A].DistanceTo(m.Vertices[mf.C]);
                    double dist2 = m.Vertices[mf.B].DistanceTo(m.Vertices[mf.D]);
                    if (dist1 > dist2)
                    {
                        projectFaces.AppendTriangle(mf.A, mf.B, mf.D);
                        projectFaces.AppendTriangle(mf.B, mf.C, mf.D);
                    }
                    else
                    {
                        projectFaces.AppendTriangle(mf.A, mf.B, mf.C);
                        projectFaces.AppendTriangle(mf.A, mf.C, mf.D);
                    }
                }
                else
                {
                    projectFaces.AppendTriangle(mf.A, mf.B, mf.C);
                }
            }

            if (rhinoInputMesh == null)
            {
                return(Result.Failure);
            }

            removeFaces.Sort();
            removeFaces.Reverse();

            foreach (var removeFace in removeFaces)
            {
                rhinoInputMesh.Faces.RemoveAt(removeFace);
            }

            rhinoInputMesh.Compact();

            GetObject goProjected = new GetObject();

            goProjected.EnablePreSelect(false, true);
            goProjected.SetCommandPrompt("Select mesh to project to");
            goProjected.GeometryFilter = ObjectType.Mesh;
            goProjected.AddOptionDouble("ConstraintAngle", ref constriantAngleOption);
            goProjected.AddOptionDouble("MinEdge", ref minEdgeLengthOption);
            goProjected.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption);
            goProjected.AddOptionInteger("SmoothSteps", ref smoothStepsOptions);
            goProjected.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption);
            goProjected.AddOptionDouble("ProjectAmount", ref projectAmountOption);
            goProjected.AddOptionDouble("ProjectDistance", ref projectedDistanceOption);

            goProjected.GroupSelect     = true;
            goProjected.SubObjectSelect = false;
            goProjected.EnableClearObjectsOnEntry(false);
            goProjected.EnableUnselectObjectsOnExit(false);


            for (; ;)
            {
                GetResult resProject = goProjected.Get();

                if (resProject == GetResult.Option)
                {
                    continue;
                }
                else if (goProjected.CommandResult() != Result.Success)
                {
                    return(goProjected.CommandResult());
                }

                break;
            }


            minEdgeLength     = minEdgeLengthOption.CurrentValue;
            maxEdgeLength     = maxEdgeLengthOption.CurrentValue;
            constriantAngle   = constriantAngleOption.CurrentValue;
            smoothSteps       = smoothStepsOptions.CurrentValue;
            smoothSpeed       = smoothSpeedOption.CurrentValue;
            projectedAmount   = projectAmountOption.CurrentValue;
            projectedDistance = projectedDistanceOption.CurrentValue;

            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++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                doc.Views.Redraw();
            }

            bool result = false;

            if (goProjected.ObjectCount < 1)
            {
                return(Result.Failure);
            }


            var rhinoMeshProject = goProjected.Object(0).Mesh();

            if (rhinoMeshProject == null || !rhinoMeshProject.IsValid)
            {
                return(Result.Failure);
            }

            var meshProjected = GopherUtil.ConvertToD3Mesh(rhinoMeshProject);

            var res = GopherUtil.RemeshMesh(projectFaces, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, meshProjected, (float)projectedAmount, (float)projectedDistance);

            var newRhinoMesh = GopherUtil.ConvertToRhinoMesh(res);

            if (newRhinoMesh != null && newRhinoMesh.IsValid)
            {
                newRhinoMesh.Append(rhinoInputMesh);

                result |= doc.Objects.Replace(rhinoMesh, newRhinoMesh);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #11
0
            protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            {
                // Command variables
                var    selectedObjects = new List <RhinoObject>();
                string selectedSchema  = "";
                bool   automatic       = true;
                bool   directShape     = false;

                // Construct an objects getter
                // This includes an option toggle for "Automatic" (true means automagic schema application, no directshapes)
                var getObj = new GetObject();

                getObj.SetCommandPrompt("Select geometry");
                var toggleAutomatic = new OptionToggle(true, "Off", "On");

                getObj.AddOptionToggle("Automatic", ref toggleAutomatic);
                getObj.GroupSelect     = true;
                getObj.SubObjectSelect = false;
                getObj.EnableClearObjectsOnEntry(false);
                getObj.EnableUnselectObjectsOnExit(false);
                getObj.DeselectAllBeforePostSelect = false;

                // Get objects
                for (; ;)
                {
                    GetResult res = getObj.GetMultiple(1, 0);
                    if (res == GetResult.Option)
                    {
                        getObj.EnablePreSelect(false, true);
                        continue;
                    }
                    else if (res != GetResult.Object)
                    {
                        return(Result.Cancel);
                    }
                    if (getObj.ObjectsWerePreselected)
                    {
                        getObj.EnablePreSelect(false, true);
                        continue;
                    }
                    break;
                }

                selectedObjects = getObj.Objects().Select(o => o.Object()).ToList();
                automatic       = toggleAutomatic.CurrentValue;

                // Construct an options getter if "Automatic" was set to "off"
                if (!automatic)
                {
                    // Construct an options getter for schema options
                    // This includes an option toggle for "DirectShape" (true will asign selected schema as the family)
                    // Also includes an option list of supported schemas
                    var getOpt = new GetOption();
                    getOpt.SetCommandPrompt("Select schema options. Press Enter when done");
                    var           toggleDirectShape     = new OptionToggle(false, "Off", "On");
                    var           directShapeIndex      = getOpt.AddOptionToggle("DirectShape", ref toggleDirectShape);
                    List <string> schemas               = Enum.GetNames(typeof(SchemaObjectFilter.SupportedSchema)).ToList();
                    int           schemaListOptionIndex = getOpt.AddOptionList("Schema", schemas, 0);

                    // Get options
                    while (getOpt.Get() == GetResult.Option)
                    {
                        if (getOpt.OptionIndex() == schemaListOptionIndex)
                        {
                            selectedSchema = schemas[getOpt.Option().CurrentListOptionIndex];
                        }
                        if (getOpt.OptionIndex() == directShapeIndex)
                        {
                            directShape = toggleDirectShape.CurrentValue;
                        }
                    }
                }

                // Apply schemas
                if (automatic)
                {
                    ApplySchemas(selectedObjects, doc);
                }
                else
                {
                    ApplySchema(selectedObjects, selectedSchema, doc, directShape);
                }
                return(Result.Success);
            }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Do some error checking first
            // If Path == nothing, ask user to save first.
            if (doc.Path == "")
            {
                System.Windows.Forms.MessageBox.Show("Please save Rhino file before you can export.", "Export Error");
                return(Result.Failure);
            }

            // Get all selected Objects
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.EnablePressEnterWhenDonePrompt(false);

            go.SetCommandPrompt("Select objects and a label to export as .DXF:");

            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Total Objects Selected: {0}", go.ObjectCount);

            string labelName = null;

            if (doc.Path == null)
            {
                System.Windows.Forms.MessageBox.Show("Please save the file as .3dm file first");
                return(Result.Failure);
            }

            if (Path.GetFileName(doc.Path).Split('.').Length == 1)
            {
                System.Windows.Forms.MessageBox.Show("Please save the file as .3dm file first");
                return(Result.Failure);
            }

            if (Path.GetFileName(doc.Path).Split('.').Length == 2 && !(Path.GetFileName(doc.Path).Split('.')[1].Equals("3dm")))
            {
                System.Windows.Forms.MessageBox.Show("Please save the file as .3dm file first");
                return(Result.Failure);
            }
            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();

                if (rhinoObject.ObjectType == ObjectType.Annotation)
                {
                    TextEntity textEntity = rhinoObject.Geometry as TextEntity;

                    if (textEntity != null)
                    {
                        labelName = CleanString(textEntity.Text.Trim()) + ".dxf";
                    }
                }
            }

            if (labelName == null)
            {
                return(Rhino.Commands.Result.Failure);
            }


            String path = Path.GetDirectoryName(doc.Path);

            // Export the whole lot
            //string command = string.Format("-_Export \"" + Path.GetDirectoryName(doc.Path) + @"\" + labelName + "\"  Scheme \"R12 Lines & Arcs\" Enter");
            string command = string.Format("-_Export \"" + Path.GetDirectoryName(doc.Path) + @"\" + labelName + "\" Enter");

            // Export the selected curves
            RhinoApp.RunScript(command, true);

            return(Result.Success);
        }
Beispiel #13
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometryFilter = ObjectType.Mesh;
            
            OptionDouble minEdgeLengthOption = new OptionDouble(minEdgeLength, 0.001, 200);
            OptionInteger maxTriangleCountOption = new OptionInteger(maxTriangleCount, 0, 100000000);
            
            GetObject go = new GetObject();
            go.SetCommandPrompt("Select meshes to reduce");
            go.GeometryFilter = geometryFilter;
            go.AddOptionDouble("MinEdge", ref minEdgeLengthOption);
            go.AddOptionInteger("MaxTriangle", ref maxTriangleCountOption);

            go.GroupSelect = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

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

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

                else if (go.CommandResult() != Result.Success)
                    return go.CommandResult();

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

                break;
            }

            maxTriangleCount = maxTriangleCountOption.CurrentValue;
            minEdgeLength = minEdgeLengthOption.CurrentValue;

            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++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                        rhinoObject.Select(false);
                }
                doc.Views.Redraw();
            }

            bool result = false;

            foreach (var obj in go.Objects())
            {
                var rhinoMesh = obj.Mesh();

                if (rhinoMesh == null || !rhinoMesh.IsValid)
                    continue;

                var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh());
                
                GopherUtil.ReduceMesh(mesh, (float)minEdgeLength, maxTriangleCount);

                double mine, maxe, avge;
                MeshQueries.EdgeLengthStats(mesh, out mine, out maxe, out avge);
                   RhinoApp.WriteLine("Edge length stats: {0} {1} {2}", mine, maxe, avge);

                var newRhinoMesh = GopherUtil.ConvertToRhinoMesh(mesh);

                if (newRhinoMesh != null && newRhinoMesh.IsValid)
                {
                    doc.Objects.Replace(obj, newRhinoMesh);
                }

                if (newRhinoMesh != null && newRhinoMesh.IsValid)
                {
                    result |= doc.Objects.Replace(obj, newRhinoMesh);
                }
            }

            doc.Views.Redraw();

            return Result.Success;
        }
        /// <summary>
        /// Creates the layout.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="panel">The panel.</param>
        /// <param name="panelParas">The panel paras.</param>
        /// <returns></returns>
        public Result createLayout(RhinoDoc doc, FoldedPerforationPanel panel, PanelParameters panelParas)
        {
            if (panelParas == null)
            {
                panelParas = new PanelParameters();
            }

            if (panel == null)
            {
                panel = new FoldedPerforationPanel();
            }

            // Get all selected Objects
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.EnablePressEnterWhenDonePrompt(false);

            go.SetCommandPrompt("Select items for the new layout:");

            // Disable the scaling
            RhinoApp.RunScript("_-DocumentProperties AnnotationStyles ModelSpaceScaling=Disabled LayoutSpaceScaling=Disabled _Enter _Enter", true);

            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Total Objects Selected: {0}", go.ObjectCount);

            string  labelName = panel.PartName;
            string  area      = string.Format("{0:0.00}", panel.Area);
            Point2d minPoint  = new Point2d(0, 0);
            Point2d maxPoint  = new Point2d(0, 0);

            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bBox = go.Object(i).Object().Geometry.GetBoundingBox(true);

                if (bBox.Min.X < minPoint.X)
                {
                    minPoint.X = bBox.Min.X;
                }

                if (bBox.Min.Y < minPoint.Y)
                {
                    minPoint.Y = bBox.Min.Y;
                }

                if (bBox.Max.X > maxPoint.X)
                {
                    maxPoint.X = bBox.Max.X;
                }

                if (bBox.Max.Y > maxPoint.Y)
                {
                    maxPoint.Y = bBox.Max.Y;
                }
            }

            // If the selected items has no label, return failure
            if (labelName == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // Hide all the non selected objects
            foreach (var obj in doc.Objects)
            {
                if (obj.IsSelected(true) == 0)
                {
                    doc.Objects.Hide(obj, false);
                }
            }

            // Add layout
            doc.PageUnitSystem = Rhino.UnitSystem.Millimeters;


            RhinoView currentView = doc.Views.ActiveView;
            var       pageview    = doc.Views.AddPageView(string.Format("{0}", labelName), 210, 297);
            Point2d   bottomLeft  = new Point2d(10, 70);
            Point2d   topRight    = new Point2d(200, 287);

            if (pageview != null)
            {
                pageview.SetPageAsActive();

                var detail = pageview.AddDetailView("Panel", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                // Show all objects
                RhinoApp.RunScript("_-Show _Enter", true);

                if (detail != null)
                {
                    pageview.SetActiveDetail(detail.Id);

                    doc.Views.ActiveView = pageview;

                    //doc.Views.Redraw();
                    // Select all the objects
                    for (int i = 0; i < go.ObjectCount; i++)
                    {
                        RhinoObject rhinoObject = go.Object(i).Object();

                        rhinoObject.Select(true);
                    }

                    // Hide all the non selected objects
                    var filter = new ObjectEnumeratorSettings
                    {
                        NormalObjects    = true,
                        LockedObjects    = false,
                        HiddenObjects    = false,
                        ActiveObjects    = true,
                        ReferenceObjects = true
                    };

                    var rh_objects = doc.Objects.FindByFilter(filter);

                    pageview.SetPageAsActive();

                    //doc.Views.Redraw();

                    foreach (var rh_obj in rh_objects)
                    {
                        var select = 0 == rh_obj.IsSelected(false) && rh_obj.IsSelectable();
                        rh_obj.Select(select);
                    }

                    RhinoApp.RunScript("_-HideInDetail Enter", true);

                    detail.IsActive = false;
                }

                bottomLeft = new Point2d(10, 40);
                topRight   = new Point2d(135, 70);

                detail = pageview.AddDetailView("Sample", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                //  doc.Views.Redraw();
                pageview.SetActiveDetail(detail.Id);

                detail.Viewport.SetCameraLocation(new Point3d(50, 160, 0), true);
                detail.CommitViewportChanges();
                //  doc.Views.Redraw();

                detail.DetailGeometry.IsProjectionLocked = true;
                detail.DetailGeometry.SetScale(4.5, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
                detail.CommitChanges();

                //  doc.Views.Redraw();


                detail.IsActive = true;
                pageview.SetActiveDetail(detail.Id);

                RhinoApp.WriteLine("Name = {0}: Width = {1}, Height = {2}",
                                   detail.Viewport.Name, detail.Viewport.Size.Width, detail.Viewport.Size.Height);
                detail.CommitViewportChanges();
                //  doc.Views.Redraw();

                detail.IsActive = false;

                bottomLeft = new Point2d(5, 5);
                topRight   = new Point2d(205, 35);
                detail     = pageview.AddDetailView("Block", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                //  doc.Views.Redraw();

                detail.IsActive = true;
                pageview.SetActiveDetail(detail.Id);

                detail.Viewport.SetCameraLocation(new Point3d(105, 520, 0), true);
                detail.CommitViewportChanges();

                //  doc.Views.Redraw();

                detail.DetailGeometry.IsProjectionLocked = true;
                detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
                detail.CommitChanges();

                detail.IsActive = false;
                //  doc.Views.Redraw();

                drawBlock(doc, labelName, area, panel.PanelNumber, panelParas);

                //  doc.Views.Redraw();
            }

            // Show all objects
            RhinoApp.RunScript("_-Show _Enter", true);

            doc.Views.DefaultViewLayout();

            doc.Views.ActiveView = currentView;

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected curve
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;

            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("{0} curve is selected.", go.ObjectCount);

            // Process the curveList and put it in a data structure
            List <Circle> circleList = new List <Circle>();

            double diameter = -1;
            Circle circle;

            for (int i = 0; i < go.ObjectCount; i++)
            {
                Curve currentCurve = go.Object(i).Curve();
                bool  converted    = currentCurve.TryGetCircle(out circle);

                if (converted == true)
                {
                    if (diameter == -1)
                    {
                        diameter = circle.Diameter;
                    }
                    else if (Math.Abs(diameter - circle.Diameter) > Properties.Settings.Default.Tolerance)
                    {
                        RhinoApp.WriteLine("Not all the curves are the same size. {0}", currentCurve.ToString());
                        return(Rhino.Commands.Result.Failure);
                    }
                }

                circleList.Add(circle);
            }

            ClusterToolSearcherForm clusterToolSearcherForm = new ClusterToolSearcherForm(circleList);

            clusterToolSearcherForm.ShowDialog(RhinoApp.MainWindow());

            //Curve curve = go.Object(0).Curve();

            //// If curve is null
            //if (curve == null)
            //{
            //   return Rhino.Commands.Result.Failure;
            //}

            //// If curve is Closed Curve Orientation
            //if (curve.IsClosed == false)
            //{
            //   RhinoApp.WriteLine("The curve is open");
            //   return Rhino.Commands.Result.Failure;
            //}

            //PerforationForm perforationForm = new PerforationForm(curve);

            //perforationForm.ShowDialog(RhinoApp.MainWindow());

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometry_filter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh;
            var integer1 = 300;
            var integer2 = 300;

            var option_integer1 = new OptionInteger(integer1, 200, 900);
            var option_integer2 = new OptionInteger(integer2, 200, 900);

            var go = new GetObject();

            go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
            go.GeometryFilter = geometry_filter;
            go.AddOptionInteger("Option1", ref option_integer1);
            go.AddOptionInteger("Option2", ref option_integer2);
            go.GroupSelect     = true;
            go.SubObjectSelect = false;

            var have_preselected_objects = false;

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

                if (res == GetResult.Option)
                {
                    go.EnablePreSelect(false, true);
                    go.AlreadySelectedObjectSelect = true;
                    go.EnableClearObjectsOnEntry(false);
                    go.DeselectAllBeforePostSelect = false;
                    go.EnableUnselectObjectsOnExit(false);
                    continue;
                }

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

                if (go.ObjectsWerePreselected)
                {
                    have_preselected_objects = true;
                    go.EnablePreSelect(false, true);
                    go.AlreadySelectedObjectSelect = true;
                    go.EnableClearObjectsOnEntry(false);
                    go.DeselectAllBeforePostSelect = false;
                    go.EnableUnselectObjectsOnExit(false);
                    continue;
                }

                break;
            }

            if (have_preselected_objects)
            {
                // 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 (var i = 0; i < go.ObjectCount; i++)
                {
                    var rhino_object = go.Object(i).Object();
                    rhino_object?.Select(false);
                }
                doc.Views.Redraw();
            }

            var object_count = go.ObjectCount;

            integer1 = option_integer1.CurrentValue;
            integer2 = option_integer2.CurrentValue;

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

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string fontName = "Dot-Matrix";
            float  fontSize = 12;

            using (System.Drawing.Font fontTester = new System.Drawing.Font(fontName, fontSize))
            {
                if (fontTester.Name == fontName)
                {
                    // Font exists do nothing
                }
                else
                {
                    RhinoApp.WriteLine("Dot Matrix Font does not exist, press install to install the font. Restart Rhino after installation.");

                    string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                    Process.Start(assemblyFolder + @"\Fonts\dotmat_0.ttf");

                    return(Rhino.Commands.Result.Failure);
                }
            }

            // Check the selected dot
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Annotation;

            go.SetCommandPrompt("Select Label and a point:");
            GetResult result = go.GetMultiple(2, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount);

            Point      pt           = null;
            TextEntity textEntity   = null;
            int        pointCounter = 0;
            int        textCounter  = 0;


            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();

                if (rhinoObject.ObjectType == ObjectType.Annotation)
                {
                    textEntity = rhinoObject.Geometry as TextEntity;

                    if (textEntity != null && textCounter == 0)
                    {
                        textCounter++;
                    }
                }
                else if (rhinoObject.ObjectType == ObjectType.Point)
                {
                    pt = rhinoObject.Geometry as Point;

                    if (pt != null && pointCounter == 0)
                    {
                        pointCounter++;
                    }
                }
            }



            //if (go.Object(0).Point() != null && go.Object(1).TextEntity() != null)
            //{
            //   pt = go.Object(0).Point();
            //   textEntity = go.Object(1).TextEntity();
            //}
            //else if (go.Object(1).Point() != null && go.Object(0).TextEntity() != null)
            //{
            //   pt = go.Object(1).Point();
            //   textEntity = go.Object(0).TextEntity();
            //}
            //else
            //{
            //   RhinoApp.WriteLine("Two of the same objects are selected.");
            //   return Result.Failure;
            //}

            if (textCounter > 1)
            {
                RhinoApp.WriteLine("More than one text has been selected.");
            }

            if (pointCounter > 1)
            {
                RhinoApp.WriteLine("More than one point has been selected.");
            }


            // Record the current layer
            int currentLayer = doc.Layers.CurrentLayerIndex;

            // Set the layer to perforation
            RhinoUtilities.SetActiveLayer(Properties.Settings.Default.DotFontLayerName, System.Drawing.Color.Black);

            if (pt != null && textEntity != null)
            {
                drawDotMatrix(pt.Location, textEntity.Text, Properties.Settings.Default.DotMatrixHeight, 80);
            }

            doc.Layers.SetCurrentLayerIndex(currentLayer, true);

            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #18
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh;

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

            for (; ;)  // infinite loop
            {
                GetResult res = go.GetMultiple(1, 0);

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

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

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

                break;
            }


            if (bHavePreselectedObjects)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                doc.Views.Redraw();
            }

            int objectCount = go.ObjectCount;

            List <String> objectTypeList = new List <string>();
            List <String> objectNameList = new List <string>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();
                string      objectName  = rhinoObject.Name;
                if (null != rhinoObject)
                {
                    objectTypeList.Add(rhinoObject.ObjectType.ToString());
                    objectNameList.Add(objectName);
                }
            }


            RhinoApp.WriteLine(string.Format("Select object count = {0}", objectCount));
            for (int i = 0; i < objectTypeList.Count; i++)
            {
                RhinoApp.WriteLine(string.Format("Select object Name : {0}, Type : {1}", objectNameList[i], objectTypeList[i]));
            }



            return(Result.Success);
        }
Beispiel #19
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected dot
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Annotation;

            go.SetCommandPrompt("Select Text to append Metrix M01:");
            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount);

            List <TextEntity>  textEntityList  = new List <TextEntity>();
            List <RhinoObject> rhinoObjectList = new List <RhinoObject>();

            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();

                if (rhinoObject.ObjectType == ObjectType.Annotation)
                {
                    TextEntity textEntity = rhinoObject.Geometry as TextEntity;

                    if (textEntity != null)
                    {
                        rhinoObjectList.Add(rhinoObject);
                        textEntityList.Add(textEntity);
                    }
                }
            }

            // Sort the text Entity list
            IEnumerable <TextEntity> query       = textEntityList.OrderByDescending(t => t.Plane.OriginY); //.ThenBy(t => t.Plane.OriginX);
            IEnumerable <TextEntity> xSortedList = textEntityList.OrderBy(t => t.Plane.OriginX);           //.ThenBy(t => t.Plane.OriginY);
            IEnumerable <TextEntity> newList     = null;
            List <TextEntity>        toSort      = new List <TextEntity>();
            List <TextEntity>        toRemove    = new List <TextEntity>();
            double  y;
            Point3d previous = new Point3d(0, 0, 0);
            int     maxDigit = (int)Math.Floor(Math.Log10(textEntityList.Count) + 1);

            int     j     = 1;
            Boolean found = false;

            foreach (TextEntity yText in query)
            {
                found = false;
                if (toRemove.Count > 0)
                {
                    foreach (TextEntity deletedElement in toRemove)
                    {
                        if (deletedElement.Equals(yText))
                        {
                            found = true;
                            break;
                        }
                    }
                }
                if (found == false)
                {
                    y      = yText.Plane.OriginY;
                    toSort = new List <TextEntity>();

                    newList = null;
                    // p = textE;
                    foreach (TextEntity t in xSortedList)
                    {
                        if (t.Plane.OriginY == y || t.Plane.OriginY >= y && t.Plane.OriginY <= (y + 200) || t.Plane.OriginY <= y && t.Plane.OriginY >= (y - 1000)) //Check if y is same
                        {
                            toSort.Add(t);
                        }
                    }

                    if (toSort.Count > 0) //If the list is more than 0, sort it by X
                    {
                        //toSort.Add(yText);
                        newList = toSort.OrderBy(t => t.Plane.OriginX);
                        toRemove.AddRange(newList);
                    }


                    foreach (TextEntity textE in newList)
                    {
                        // Test if there is a M_- in front of the text, if yes, remove it
                        if (textE.Text.Count() > 2)
                        {
                            if (textE.Text[0] == 'M')
                            {
                                if (Char.IsNumber(textE.Text[1]))
                                {
                                    if (textE.Text.IndexOf('-') != -1)
                                    {
                                        // This means M0 exist
                                        textE.Text = textE.Text.Substring(textE.Text.IndexOf('-') + 1);
                                    }
                                }
                            }
                        }

                        textE.Text = "M" + j.ToString().PadLeft(maxDigit, '0') + "-" + textE.Text;
                        j++;
                    }
                    //  toRemove.AddRange(newList);
                }
                else
                {
                    continue;
                }
            }


            // Commit the changes for all updated labels
            for (int k = 0; k < rhinoObjectList.Count; k++)
            {
                rhinoObjectList[k].CommitChanges();
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
        ///<summary>The only instance of this command.</summary>
        ///<param name="doc" RhinoDoc></param>
        ///<param name="mode" Run mode></param>
        ///<returns>returns sucess if doc is successfully created </returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            #region set all the file parameters

            pdfOptionForm = new PDFOptionForm();
            Application.Run(pdfOptionForm);
            getSelectedOption = PDFOptionForm.optionsSelected;

            myUniqueFileName = string.Format(@"{0}" + ext, Guid.NewGuid());
            string logFilePath = Rhino.ApplicationSettings.FileSettings.WorkingFolder + "\\Log-" + DateTime.Now.GetHashCode().ToString() + ".txt";
            string curveType   = "C";
            try
            {
                string[] checkFileName = Rhino.ApplicationSettings.FileSettings.RecentlyOpenedFiles()[0].ToString().Split('\\');
                int      checklength   = checkFileName.Length;
                rhinoFile = Rhino.ApplicationSettings.FileSettings.RecentlyOpenedFiles()[0].ToString().Split('\\')[--checklength];
            }
            catch (FileNotFoundException fnf) { logFile(fnf.Message); }
            catch (IndexOutOfRangeException ioor) { logFile(ioor.Message); }

            string rhinoFileName = rhinoFile.Split('.')[0];
            string filename      = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + rhinoFileName + "-" + myUniqueFileName;

            #endregion

            Rhino.RhinoApp.RunScript("-_Save Enter", false);

            logFile("Process started for ---> " + rhinoFileName + "-" + myUniqueFileName);

            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            XGraphics gfx  = XGraphics.FromPdfPage(page);
            XFont     font = new XFont("Verdana", 20, XFontStyle.Bold);

            #region Check the selected curve
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = ObjectType.AnyObject;

            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("{0} objects are selected.", go.ObjectCount);

            #endregion

            // Process the list of objects
            logFile("Processing List of Object");

            #region set the paramenters for Xgraph to process shapes

            List <GeometryBase> geoList = new List <GeometryBase>();

            double minX, minY, maxX, maxY;
            minX = double.MaxValue;
            minY = double.MaxValue;

            maxX = double.MinValue;
            maxY = double.MinValue;

            List <Curve>      curveList      = new List <Curve>();
            List <TextEntity> textEntityList = new List <TextEntity>();

            List <Circle>   circleList = new List <Circle>();
            List <Polyline> polyList   = new List <Polyline>();
            Circle          circleCurve;
            Polyline        polygon;

            #endregion

            for (int i = 0; i < go.ObjectCount; i++)
            {
                // Check the type of the Object and process differently
                Curve curve = go.Object(i).Curve();

                if (go.Object(i).Curve().TryGetCircle(out circleCurve))
                {
                    circleList.Add(circleCurve);
                }
                if (go.Object(i).Curve().TryGetPolyline(out polygon))
                {
                    polyList.Add(polygon);
                }
                if (curve != null)
                {
                    curveList.Add(curve);
                }

                TextEntity te = go.Object(i).TextEntity();

                if (te != null)
                {
                    textEntityList.Add(te);
                }

                GeometryBase geo  = go.Object(i).Geometry();
                BoundingBox  bbox = geo.GetBoundingBox(Rhino.Geometry.Plane.WorldXY);

                if (bbox.Min.X < minX)
                {
                    minX = bbox.Min.X;
                }
                if (bbox.Min.Y < minY)
                {
                    minY = bbox.Min.Y;
                }
                if (bbox.Max.X > maxX)
                {
                    maxX = bbox.Max.X;
                }
                if (bbox.Max.Y > maxY)
                {
                    maxY = bbox.Max.Y;
                }

                geoList.Add(geo);
            }

            page.Height = maxY - minY;
            page.Width  = maxX - minX;


            foreach (GeometryBase g in geoList)
            {
                if (g.GetType().Equals(typeof(PolyCurve)))
                {
                    //System.Windows.Forms.MessageBox.Show("PolyCurve changed");
                    PolyCurve polyCurve = (PolyCurve)g;
                    curveType = "NC";
                    break;
                }
                else if (g.GetType().Equals(typeof(Curve)))
                {
                    System.Windows.Forms.MessageBox.Show("Curve");
                    Curve curve = (Curve)g;
                }
                else if (g.GetType().Equals(typeof(TextEntity)))
                {
                    System.Windows.Forms.MessageBox.Show("TextEntity");
                    TextEntity textEntity = (TextEntity)g;
                    curveType = "T";
                }
            }

            logFile("Checking the pattern");
            if (curveType.Equals("C") || curveType.Equals("T"))
            {
                logFile("Objects processed sucessfully");

                double x1, y1, width, height;

                logFile("Creating Circles on the PDF");
                //Loop to draw the circles
                foreach (Circle c in circleList)
                {
                    XPen pen = new XPen(XColors.Black, 0.5);
                    x1     = c.BoundingBox.Min.X - minX;
                    y1     = maxY - c.BoundingBox.Max.Y;
                    width  = c.BoundingBox.Max.X - c.BoundingBox.Min.X;
                    height = c.BoundingBox.Max.Y - c.BoundingBox.Min.Y;
                    gfx.DrawEllipse(XBrushes.Black, x1, y1, width, height);
                }

                //Loop used to draw rectangles
                foreach (Polyline p in polyList)
                {
                    XPen pen = new XPen(XColors.Black, 0.5);
                    x1     = p.BoundingBox.Min.X - minX;
                    y1     = maxY - p.BoundingBox.Max.Y;
                    width  = p.BoundingBox.Max.X - p.BoundingBox.Min.X;
                    height = p.BoundingBox.Max.Y - p.BoundingBox.Min.Y;
                    XPoint   p1     = new XPoint(x1, y1);
                    XPoint   p2     = new XPoint(x1 + width, y1);
                    XPoint   p3     = new XPoint(x1, y1 + height);
                    XPoint   p4     = new XPoint(x1 + width, y1 + height);
                    XRect    rect   = new XRect(x1, y1, width, height);
                    XPoint[] xPoint = new XPoint[] { p1, p2, p4, p3 };
                    //XPoint mid = new XPoint( (x1 + x1)/2);
                    XGraphicsState gs = gfx.Save();
                    gfx.RotateAtTransform(-45, p1);
                    gfx.DrawPolygon(pen, XBrushes.Black, xPoint, XFillMode.Alternate);
                    gfx.Restore(gs);
                }



                #region Print the PDF as per the option selected
                if (getSelectedOption.Equals('N'))
                {
                    logFile("Normal PDF feature was selected");
                    document.Save(filename);
                    logFile("Document saved successfully - " + Rhino.ApplicationSettings.FileSettings.WorkingFolder);
                }
                if (getSelectedOption.Equals('C'))
                {
                    logFile("Compressed PDF feature was selected");
                    CompressMyPdf(document);
                    string compressedFileName = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "C-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(compressedFileName);
                }
                if (getSelectedOption.Equals('E'))
                {
                    logFile("Encrypted PDF feature was selected");
                    EncryptMyPdf(document);
                    string encryptPdf = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "E-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(encryptPdf);
                }
                if (getSelectedOption.Equals('P'))
                {
                    logFile("Password Protection PDF feature was selected");
                    PasswordProtectMyPdf(document);
                    string passwordProtectPdf = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "PP-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(passwordProtectPdf);
                }

                #endregion

                logFile("Document saved successfully - " + Rhino.ApplicationSettings.FileSettings.WorkingFolder);

                logFile("Panel perforated successfully. Check File --> " + rhinoFileName + "-" + myUniqueFileName);
                System.Windows.Forms.MessageBox.Show("         <----SUCCESS---->       " + Environment.NewLine + Environment.NewLine + " Pannels perforated Successfully. ");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("                           ERROR!     " + Environment.NewLine + Environment.NewLine + "The curve you have selected contains some invalid shape." + Environment.NewLine + " Please select the appropriate patterns. ");
                logFile("Please select the appropriate pattern");
            }

            logFile("----------------- WAITING FOR THE NEXT PANEL PERFORATION ---------------------");

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometryFilter = ObjectType.Mesh;

            OptionDouble  minEdgeLengthOption     = new OptionDouble(minEdgeLength, 0.001, 200);
            OptionDouble  maxEdgeLengthOption     = new OptionDouble(maxEdgeLength, 0.001, 200);
            OptionDouble  constriantAngleOption   = new OptionDouble(constriantAngle, 0.001, 360);
            OptionInteger smoothStepsOptions      = new OptionInteger(smoothSteps, 0, 1000);
            OptionDouble  smoothSpeedOption       = new OptionDouble(smoothSpeed, 0.01, 1.0);
            OptionDouble  projectAmountOption     = new OptionDouble(projectedAmount, 0.01, 1.0);
            OptionDouble  projectedDistanceOption = new OptionDouble(projectedDistance, 0.01, 100000.0);

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select mesh to remesh");
            go.GeometryFilter = geometryFilter;
            go.AddOptionDouble("ConstraintAngle", ref constriantAngleOption);
            go.AddOptionDouble("MinEdge", ref minEdgeLengthOption);
            go.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption);
            go.AddOptionInteger("SmoothSteps", ref smoothStepsOptions);
            go.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption);
            go.AddOptionDouble("ProjectAmount", ref projectAmountOption);
            go.AddOptionDouble("ProjectDistance", ref projectedDistanceOption);

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

            for (;;)
            {
                GetResult res = go.Get();

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

                else if (go.CommandResult() != Result.Success)
                {
                    return(go.CommandResult());
                }

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

                break;
            }

            GetObject goProjected = new GetObject();

            goProjected.EnablePreSelect(false, true);
            goProjected.SetCommandPrompt("Select mesh to project to");
            goProjected.GeometryFilter = geometryFilter;
            goProjected.AddOptionDouble("ConstraintAngle", ref constriantAngleOption);
            goProjected.AddOptionDouble("MinEdge", ref minEdgeLengthOption);
            goProjected.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption);
            goProjected.AddOptionInteger("SmoothSteps", ref smoothStepsOptions);
            goProjected.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption);
            goProjected.AddOptionDouble("ProjectAmount", ref projectAmountOption);
            goProjected.AddOptionDouble("ProjectDistance", ref projectedDistanceOption);

            goProjected.GroupSelect     = true;
            goProjected.SubObjectSelect = false;
            goProjected.EnableClearObjectsOnEntry(false);
            goProjected.EnableUnselectObjectsOnExit(false);


            for (;;)
            {
                GetResult res = goProjected.Get();

                if (res == GetResult.Option)
                {
                    continue;
                }

                else if (goProjected.CommandResult() != Result.Success)
                {
                    return(goProjected.CommandResult());
                }

                break;
            }


            minEdgeLength     = minEdgeLengthOption.CurrentValue;
            maxEdgeLength     = maxEdgeLengthOption.CurrentValue;
            constriantAngle   = constriantAngleOption.CurrentValue;
            smoothSteps       = smoothStepsOptions.CurrentValue;
            smoothSpeed       = smoothSpeedOption.CurrentValue;
            projectedAmount   = projectAmountOption.CurrentValue;
            projectedDistance = projectedDistanceOption.CurrentValue;

            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++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                doc.Views.Redraw();
            }

            bool result = false;

            if (goProjected.ObjectCount < 1)
            {
                return(Result.Failure);
            }

            foreach (var obj in go.Objects())
            {
                var rhinoMesh = obj.Mesh();

                if (rhinoMesh == null || !rhinoMesh.IsValid)
                {
                    continue;
                }

                var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh());


                var rhinoMeshProject = goProjected.Object(0).Mesh();

                if (rhinoMeshProject == null || !rhinoMeshProject.IsValid)
                {
                    continue;
                }

                var meshProjected = GopherUtil.ConvertToD3Mesh(rhinoMeshProject);

                var mesh2 = new DMesh3(mesh);
                var mesh3 = new DMesh3(mesh);

                var res3 = GopherUtil.RemeshMesh(mesh3, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, meshProjected, (float)projectedAmount, (float)projectedDistance);

                var watch = System.Diagnostics.Stopwatch.StartNew();
                // the code that you want to measure comes here

                var res = GopherUtil.RemeshMesh(mesh, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, meshProjected, (float)projectedAmount, (float)projectedDistance);

                watch.Stop();

                var watch2 = System.Diagnostics.Stopwatch.StartNew();

                var res2 = GopherUtil.RemeshMeshNew(mesh2, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, meshProjected, (float)projectedAmount, (float)projectedDistance);

                watch2.Stop();


                Rhino.RhinoApp.WriteLine("Time 1: {0} Time 2: {1}", watch.ElapsedMilliseconds, watch2.ElapsedMilliseconds);

                var newRhinoMesh = GopherUtil.ConvertToRhinoMesh(res);

                var newRhinoMesh2 = GopherUtil.ConvertToRhinoMesh(mesh2);

                newRhinoMesh2.Translate(new Rhino.Geometry.Vector3d(newRhinoMesh2.GetBoundingBox(true).Diagonal.X, 0, 0));

                doc.Objects.Add(newRhinoMesh2);

                if (newRhinoMesh != null && newRhinoMesh.IsValid)
                {
                    doc.Objects.Replace(obj, newRhinoMesh);
                }

                if (newRhinoMesh != null && newRhinoMesh.IsValid)
                {
                    result |= doc.Objects.Replace(obj, newRhinoMesh);
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected dot
            GetObject go = new GetObject();

            // Create a new dictionary of strings, with string keys.
            //
            Dictionary <int, int> sizeAngle    = new Dictionary <int, int>();
            List <int>            holeSizeList = new List <int>();

            //Setting up for hole selection
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;

            go.SetCommandPrompt("Select all the circles:");
            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount);

            List <RhinoObject> rhinoObjectList = new List <RhinoObject>();
            List <ArcCurve>    arcCurveList    = new List <ArcCurve>();

            // Loop through all the objects to find Curve
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();

                if (rhinoObject.ObjectType == ObjectType.Curve)
                {
                    ArcCurve curve = rhinoObject.Geometry as ArcCurve;

                    if (curve != null)
                    {
                        if (curve.IsCircle() == true)
                        {
                            if (!holeSizeList.Exists(element => element == curve.Radius))
                            {
                                holeSizeList.Add(Convert.ToInt32(curve.Radius)); //add unique hole sizes
                            }

                            arcCurveList.Add(curve);
                        }
                    }
                }
            }

            holeSizeList.Sort();

            int maxHole = Convert.ToInt32(holeSizeList.Max());           //get the maximum hole size in the list
            int minHole = Convert.ToInt32(holeSizeList.Min());           //get the minimum hole size in the list

            double maximumRotation = (360 - (360 / holeSizeList.Count)); //equation to calculate the maximum rotation
            int    indexCOunt      = 0;

            foreach (int size in holeSizeList) //for each hole size in the list, calculate the angle of rotation
            {
                int angle;
                if ((maxHole - minHole) != 0)
                {
                    angle = Convert.ToInt32(indexCOunt * (360 / holeSizeList.Count));
                    indexCOunt++;
                }
                else
                {
                    angle = 0;
                }

                sizeAngle.Add(size, angle); //assign the angle for each hole size
            }

            // Create a new layer
            string layerName = "CaveTool";

            // Does a layer with the same name already exist?
            int layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            String location = getCaveToolLocation(); //get the location of the cave tool (request from user)

            if (location != null)
            {
                //for each hole found (selected by user)
                //start drawing the cave tool
                foreach (ArcCurve ac in arcCurveList)
                {
                    int angle = 0;
                    //pass the hole size and get the angle  specific to the hole size
                    sizeAngle.TryGetValue(Convert.ToInt32(ac.Radius), out angle);
                    //draw the cave tool
                    drawCaveImageTool(ac.Arc.Center.X, ac.Arc.Center.Y, angle, layerIndex, location);
                }
            }
            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            using (var go = new GetObject())
            {
                go.SetCommandPrompt("Please select closed objects for converting to Honeybee Room");

                //Only Brep is accepted, because we need to save meta data to sub-surface as well.
                //Extrusion doesn't have sub-surface.
                //all extrusion will be converted to Brep.
                go.GeometryFilter = ObjectType.Brep | ObjectType.Extrusion;
                go.EnableClearObjectsOnEntry(false);
                go.EnableUnselectObjectsOnExit(false);
                go.DeselectAllBeforePostSelect = false;

                //check if any brep has been converted to Room
                var optionSkipExistingRoom_toggle = new OptionToggle(true, "No_RecreateAllRooms", "Yes");
                while (true)
                {
                    go.ClearCommandOptions();
                    go.AddOptionToggle("SkipExistingRoom", ref optionSkipExistingRoom_toggle);
                    var rc = go.GetMultiple(1, 0);
                    if (rc == GetResult.Option)
                    {
                        go.EnablePreSelect(false, true);
                        continue;
                    }
                    else if (rc != GetResult.Object)
                    {
                        return(Result.Cancel);
                    }
                    if (go.ObjectsWerePreselected)
                    {
                        go.EnablePreSelect(false, true);
                        continue;
                    }
                    break;
                }

                if (go.CommandResult() != Result.Success)
                {
                    return(Result.Failure);
                }

                if (go.ObjectCount == 0)
                {
                    return(Result.Nothing);
                }

                var ifSkip = optionSkipExistingRoom_toggle.CurrentValue;

                //Getting objects
                var solidBreps      = go.Objects().Where(_ => _.Brep() != null).Where(_ => _.Brep().IsSolid);
                var objectToConvert = solidBreps;
                if (ifSkip)
                {
                    objectToConvert = solidBreps.Where(_ => !_.IsRoom()).ToList();
                }

                ConvertToRoom(doc, objectToConvert);

                doc.Views.Redraw();

                var count = objectToConvert.Count();
                var msg   = count > 1 ? $"{count} Honeybee rooms were created successfully!" : $"{count} Honeybee room was created successfully!";
                RhinoApp.WriteLine(msg);
                return(Result.Success);
            }
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometryFilter = ObjectType.Mesh;

            OptionDouble  minEdgeLengthOption   = new OptionDouble(minEdgeLength, 0.001, 200);
            OptionDouble  maxEdgeLengthOption   = new OptionDouble(maxEdgeLength, 0.001, 200);
            OptionDouble  constriantAngleOption = new OptionDouble(constriantAngle, 0.001, 360);
            OptionInteger smoothStepsOptions    = new OptionInteger(smoothSteps, 0, 10000);
            OptionDouble  smoothSpeedOption     = new OptionDouble(smoothSpeed, 0.01, 1.0);

            GetObject go = new GetObject();

            go.SetCommandPrompt("Select meshes to remesh");
            go.GeometryFilter = geometryFilter;
            go.AddOptionDouble("ConstraintAngle", ref constriantAngleOption);
            go.AddOptionDouble("MinEdge", ref minEdgeLengthOption);
            go.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption);
            go.AddOptionInteger("SmoothSteps", ref smoothStepsOptions);
            go.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption);

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

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

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

                else if (go.CommandResult() != Result.Success)
                {
                    return(go.CommandResult());
                }

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

                break;
            }

            minEdgeLength   = minEdgeLengthOption.CurrentValue;
            maxEdgeLength   = maxEdgeLengthOption.CurrentValue;
            constriantAngle = constriantAngleOption.CurrentValue;
            smoothSteps     = smoothStepsOptions.CurrentValue;
            smoothSpeed     = smoothSpeedOption.CurrentValue;

            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++)
                {
                    RhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                doc.Views.Redraw();
            }

            bool result = false;

            foreach (var obj in go.Objects())
            {
                var rhinoMesh = obj.Mesh();

                if (rhinoMesh == null || !rhinoMesh.IsValid)
                {
                    continue;
                }

                var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh());

                var res = GopherUtil.RemeshMesh(mesh, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps);

                var newRhinoMesh = GopherUtil.ConvertToRhinoMesh(mesh);

                if (newRhinoMesh != null && newRhinoMesh.IsValid)
                {
                    doc.Objects.Replace(obj, newRhinoMesh);
                }

                if (newRhinoMesh != null && newRhinoMesh.IsValid)
                {
                    result |= doc.Objects.Replace(obj, newRhinoMesh);
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #25
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected dot
            GetObject go = new GetObject();

            // Create a new dictionary of strings, with string keys.
            //
            Dictionary <double, double> sizeAngle = new Dictionary <double, double>();
            List <double> holeSizeList            = new List <double>();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;

            go.SetCommandPrompt("Select all the circles:");
            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount);

            List <RhinoObject> rhinoObjectList = new List <RhinoObject>();
            List <ArcCurve>    arcCurveList    = new List <ArcCurve>();

            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();

                if (rhinoObject.ObjectType == ObjectType.Curve)
                {
                    ArcCurve curve = rhinoObject.Geometry as ArcCurve;

                    if (curve != null)
                    {
                        if (curve.IsCircle() == true)
                        {
                            if (!holeSizeList.Exists(element => element == curve.Radius))
                            {
                                holeSizeList.Add(curve.Radius);
                            }

                            arcCurveList.Add(curve);
                            // rhinoObjectList.Add(rhinoObject);
                        }
                    }
                }
            }

            holeSizeList.Sort();

            if (holeSizeList.Count < 1)
            {
                return(Result.Failure);
            }

            double maxHole = holeSizeList.Max();
            double minHole = holeSizeList.Min();

            foreach (double size in holeSizeList)
            {
                double angle;
                if ((maxHole - minHole) != 0)
                {
                    angle = 180 * ((size - minHole) / (maxHole - minHole));
                }
                else
                {
                    angle = 0;
                }

                sizeAngle.Add(size, angle);
            }

            // Create a new layer
            string layerName = "FormTool";

            // Does a layer with the same name already exist?
            int layerIndex = doc.Layers.Find(layerName, true);

            // If layer does not exist
            if (layerIndex == -1)
            {
                // Add a new layer to the document
                layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black);
            }

            doc.Layers.SetCurrentLayerIndex(layerIndex, true);

            foreach (ArcCurve ac in arcCurveList)
            {
                double angle = 0;

                sizeAngle.TryGetValue(ac.Radius, out angle);

                drawFormTool(ac.Arc.Center.X, ac.Arc.Center.Y, angle * Math.PI / 180);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #26
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected dot
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Annotation;

            go.SetCommandPrompt("Select Text to append Metrix M01:");
            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount);

            List <TextEntity>  textEntityList  = new List <TextEntity>();
            List <RhinoObject> rhinoObjectList = new List <RhinoObject>();

            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();

                if (rhinoObject.ObjectType == ObjectType.Annotation)
                {
                    TextEntity textEntity = rhinoObject.Geometry as TextEntity;

                    if (textEntity != null)
                    {
                        rhinoObjectList.Add(rhinoObject);
                        textEntityList.Add(textEntity);
                    }
                }
            }

            // Sort the text Entity list
            IEnumerable <TextEntity> query = textEntityList.OrderByDescending(t => t.Plane.OriginY).ThenBy(t => t.Plane.OriginX);

            int maxDigit = (int)Math.Floor(Math.Log10(textEntityList.Count) + 1);

            int j = 1;

            foreach (TextEntity textE in query)
            {
                textE.Text = textE.Text + "-Q1";
                j++;
            }


            // Commit the changes for all updated labels
            for (int k = 0; k < rhinoObjectList.Count; k++)
            {
                rhinoObjectList[k].CommitChanges();
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;

            go.SetCommandPrompt("Select All circles you want to filter:");
            GetResult result = go.GetMultiple(1, 0);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            int fixingHoleCounter = go.ObjectCount;

            RhinoApp.WriteLine("circle selection counter = {0}", fixingHoleCounter);

            int i = 0;

            Point3d[]     fixingHole  = new Point3d[fixingHoleCounter];
            double[]      fixingHoleD = new double[fixingHoleCounter];
            RhinoObject[] references  = new RhinoObject[fixingHoleCounter];

            for (i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();
                Curve       curve       = (new ObjRef(rhinoObject)).Curve();
                if (curve == null)
                {
                    continue;
                }

                if (curve.IsClosed == false)
                {
                    continue;
                }

                if (curve.IsPlanar() == false)
                {
                    continue;
                }

                if (curve.IsCircle())
                {
                    BoundingBox boundingBox = curve.GetBoundingBox(true);
                    fixingHoleD[i] = boundingBox.Max.X - boundingBox.Min.X;
                    fixingHole[i]  = boundingBox.Center;
                    references[i]  = rhinoObject;
                }
            }

            //Get the gap clearance offset
            go.SetCommandPrompt("Enter detection radius:");
            go.AcceptNumber(true, false);
            go.Get();
            double offset = go.Number();

            double perforationHoldD;
            string layerName = "";


            //for testing purpose, draw the hole with offset using red color

            /*Curve[] circles = new Curve[fixingHole.Length];
             * for (i = 0; i < circles.Length; i++)
             * {
             *
             *  circles[i] = new ArcCurve(new Circle(fixingHole[i], offset));
             * }
             *
             *
             * if (circles != null)
             * {
             *  layerName = offset + "mm GAP CLEARANCE";
             *  RhinoUtilities.SetActiveLayer(layerName, System.Drawing.Color.Red);
             *
             *  foreach (Curve cv in circles)
             *  {
             *      Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(cv);
             *  }
             * }*/

            string clashHoleLayerName = "HOLES CLASHED";
            Layer  clashHoleLayer     = new Layer();

            clashHoleLayer.Name  = clashHoleLayerName;
            clashHoleLayer.Color = System.Drawing.Color.Red;

            int clashHoleLayerIndex = doc.Layers.Add(clashHoleLayer);
            int currentHoleCounter;
            int flag;

            bool[] deletedCircles = new bool[fixingHole.Length];
            for (i = 0; i < deletedCircles.Length; i++)
            {
                deletedCircles[i] = false;
            }

            Curve circles;

            RhinoUtilities.SetActiveLayer(clashHoleLayerName, System.Drawing.Color.Red);
            for (i = 0; i < fixingHole.Length - 1; i++)
            {
                currentHoleCounter = 0;
                flag = 0;
                for (int j = i + 1; j < fixingHole.Length; j++)
                {
                    if (deletedCircles[j] == true)
                    {
                        continue;
                    }
                    if (fixingHole[i].DistanceTo(fixingHole[j]) < fixingHoleD[i] + offset)
                    {
                        if (currentHoleCounter == 0)
                        {
                            flag = j;
                            currentHoleCounter++;
                        }
                        else
                        {
                            currentHoleCounter++;
                            break;
                        }
                    }
                    if (currentHoleCounter == 1)
                    {
                        circles = new ArcCurve(new Circle(fixingHole[flag], fixingHoleD[flag] / 2));
                        Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(circles);

                        RhinoDoc.ActiveDoc.Objects.Delete(references[flag], false);
                        deletedCircles[flag] = true;
                    }
                    else if (currentHoleCounter == 2)
                    {
                        circles = new ArcCurve(new Circle(fixingHole[i], fixingHoleD[i] / 2));
                        Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(circles);

                        RhinoDoc.ActiveDoc.Objects.Delete(references[i], false);
                        deletedCircles[i] = true;
                    }
                }
            }


            RhinoUtilities.setLayerVisibility("HOLES CLASHED", true);

            RhinoUtilities.setLayerVisibility(layerName, false);

            doc.Views.Redraw();

            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("CurveToCircle");

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



            GetObject gc = new GetObject();

            gc.SetCommandPrompt("Select curves to make into circles");
            gc.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
            gc.GroupSelect     = true;
            gc.SubObjectSelect = false;
            gc.EnableClearObjectsOnEntry(false);
            gc.EnableUnselectObjectsOnExit(false);
            gc.DeselectAllBeforePostSelect = false;
            gc.GetMultiple(1, 0);

            for (int i = 0; i < gc.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = gc.Object(i);
                var curve = objref.Curve();
                if (curve == null)
                {
                    return(Result.Nothing);
                }

                Circle circle;

                if (!curve.TryGetCircle(out circle))
                {
                    if (!curve.IsClosed)
                    {
                        if (curve.IsClosable(doc.ModelAbsoluteTolerance))
                        {
                            curve.MakeClosed(doc.ModelAbsoluteTolerance);
                        }
                        else
                        {
                            Curve blendCurve;
                            blendCurve = Curve.CreateBlendCurve(curve, curve, BlendContinuity.Curvature);
                            Curve[] curveSet    = { curve, blendCurve };
                            Curve[] joinedCurve = Curve.JoinCurves(curveSet);
                            curve = joinedCurve[0];
                        }
                    }

                    //curve.Rebuild(3,2,true);
                    double[]  curveDivide = curve.DivideByCount(8, true);
                    Point3d   curvePoint;
                    Point3d[] curvePoints = new Point3d[8];
                    for (int d = 0; d < 8; d++)
                    {
                        curvePoint     = curve.PointAt(curveDivide[d]);
                        curvePoints[d] = curvePoint;
                    }

                    if (!Circle.TryFitCircleToPoints(curvePoints, out circle))
                    {
                        circle = new Circle(5);
                    }
                }



                var circGuid = doc.Objects.AddCircle(circle);
                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(circGuid);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();
            }


            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #29
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected dot
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Annotation;


            go.SetCommandPrompt("Select Label and a point:");
            GetResult result = go.GetMultiple(2, -1);



            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount);

            Point      pt           = null;
            TextEntity textEntity   = null;
            int        pointCounter = 0;
            int        textCounter  = 0;


            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();

                if (rhinoObject.ObjectType == ObjectType.Annotation)
                {
                    textEntity = rhinoObject.Geometry as TextEntity;

                    if (textEntity != null && textCounter == 0)
                    {
                        textCounter++;
                    }
                }
                else if (rhinoObject.ObjectType == ObjectType.Point)
                {
                    pt = rhinoObject.Geometry as Point;

                    if (pt != null && pointCounter == 0)
                    {
                        pointCounter++;
                    }
                }
            }



            //if (go.Object(0).Point() != null && go.Object(1).TextEntity() != null)
            //{
            //   pt = go.Object(0).Point();
            //   textEntity = go.Object(1).TextEntity();
            //}
            //else if (go.Object(1).Point() != null && go.Object(0).TextEntity() != null)
            //{
            //   pt = go.Object(1).Point();
            //   textEntity = go.Object(0).TextEntity();
            //}
            //else
            //{
            //   RhinoApp.WriteLine("Two of the same objects are selected.");
            //   return Result.Failure;
            //}

            if (textCounter > 1)
            {
                RhinoApp.WriteLine("More than one text has been selected.");
            }

            if (pointCounter > 1)
            {
                RhinoApp.WriteLine("More than one point has been selected.");
            }


            if (pt != null && textEntity != null)
            {
                drawDotMatrix(pt.Location, textEntity.Text, Properties.Settings.Default.DotMatrixHeight);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            // List of Object Types to filter
            List <ObjectType> enumList = new List <ObjectType> {
                ObjectType.Point,
                ObjectType.Curve,
                ObjectType.Extrusion,
                ObjectType.Surface,
                ObjectType.Brep,
                ObjectType.Mesh,
                ObjectType.InstanceReference,
                ObjectType.Light,
                ObjectType.ClipPlane,
                ObjectType.Hatch,
                ObjectType.Annotation,
                ObjectType.ClipPlane,
            };

            string[]            enumNames  = Enum.GetNames(typeof(ObjectType));
            var                 enumValues = Enum.GetValues(typeof(ObjectType)).OfType <ObjectType>().ToList();
            List <OptionToggle> options    = new List <OptionToggle>();
            List <ObjectType>   types      = new List <ObjectType>();

            for (int i = 0; i < enumList.Count; i++)
            {
                var value = (ObjectType)enumList[i];
                var index = enumValues.IndexOf(value);

                if (index > -1)
                {
                    var toggle = new OptionToggle(false, "Off", "On");
                    options.Add(toggle);
                    types.Add(value);
                    go.AddOptionToggle(enumNames[index], ref toggle);
                }
            }

            go.SetCommandPrompt("Select filter geometry types");

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            var selectedObjectTypes = new List <ObjectType>();

            while (true)
            {
                GetResult res = go.GetMultiple(1, 0);


                // If the action is change in filter, update the filter list.
                if (res == GetResult.Option)
                {
                    selectedObjectTypes.Clear();
                    go.EnablePreSelect(false, true);
                    ObjectType objectTypes = 0;
                    for (var i = 0; i < options.Count; i++)
                    {
                        var type = types[i];
                        if (options[i].CurrentValue)
                        {
                            selectedObjectTypes.Add(type);
                            if (objectTypes == ObjectType.None)
                            {
                                objectTypes = type;
                            }
                            else
                            {
                                objectTypes |= type;
                            }
                        }
                    }
                    go.GeometryFilter = objectTypes;

                    continue;
                }

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

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

                break;
            }

            // Select objects that meets the filter criteria
            for (int i = 0; i < go.ObjectCount; i++)
            {
                RhinoObject rhinoObject = go.Object(i).Object();
                if (null != rhinoObject)
                {
                    if (selectedObjectTypes.Contains(rhinoObject.ObjectType))
                    {
                        rhinoObject.Select(true);
                    }
                    else
                    {
                        rhinoObject.Select(false);
                    }
                }
            }
            doc.Views.Redraw();
            return(Result.Success);
        }