Exemplo n.º 1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Get persistent settings (from Registry)
            PersistentSettings settings = this.PlugIn.Settings;
            bool save_settings          = false;
            bool enabled = settings.GetBool("enabled", true);
            bool new_layer_visible_in_layout = settings.GetBool("new_layer_visible_in_layout", false);

            GetOption    go = new GetOption();
            OptionToggle option_toggle_enabled = new OptionToggle(enabled, "off", "on");
            OptionToggle option_toggle_newLayerLayoutVisible = new OptionToggle(new_layer_visible_in_layout, "off", "on");

            go.AddOptionToggle("enabled", ref option_toggle_enabled);
            go.AddOptionToggle("new_layer_visible_in_layout", ref option_toggle_newLayerLayoutVisible);
            go.SetCommandPrompt("Safe Layout Settings");

            Rhino.Input.GetResult get_rc = go.Get();
            Result rc = go.CommandResult();

            if (enabled != option_toggle_enabled.CurrentValue)
            {
                enabled = option_toggle_enabled.CurrentValue;
                settings.SetBool("enabled", enabled);
                save_settings = true;
            }
            if (new_layer_visible_in_layout != option_toggle_newLayerLayoutVisible.CurrentValue)
            {
                new_layer_visible_in_layout = option_toggle_newLayerLayoutVisible.CurrentValue;
                settings.SetBool("new_layer_visible_in_layout", new_layer_visible_in_layout);
                save_settings = true;
            }

            if (save_settings)
            {
                this.PlugIn.SaveSettings();
            }

            return(rc);
        }
Exemplo n.º 2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetOption go = new GetOption();
            go.SetCommandPrompt("Set Faro scan settings");

            Rhino.Input.Custom.GetString gs = new GetString();
            gs.SetCommandPrompt("Set Faro IP address.");
            gs.SetDefaultString("127.0.0.1");

            gs.AddOption("Scanner IP");

            gs.Get();

            string val = gs.StringResult();

            Rhino.RhinoApp.WriteLine("IP: " + val);

            // set up the options
            Rhino.Input.Custom.OptionInteger intOption  = new Rhino.Input.Custom.OptionInteger(1, 1, 99);
            Rhino.Input.Custom.OptionDouble  dblOption  = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9);
            Rhino.Input.Custom.OptionToggle  boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On");
            string[] resolutionValues  = new string[] { "Full", "Half", "Quarter", "Eighth", "Sixsteenth" };
            string[] measurementValues = new string[] { "Low", "Medium", "High" };
            string[] noiseValues       = new string[] { "Low", "Medium", "High" };


            go.AddOptionInteger("Integer", ref intOption);
            go.AddOptionDouble("Double", ref dblOption);
            go.AddOptionToggle("Boolean", ref boolOption);

            int resolutionIndex  = 2;
            int measurementIndex = 1;
            int noiseIndex       = 1;

            int resolutionList  = go.AddOptionList("Resolution", resolutionValues, resolutionIndex);
            int measurementList = go.AddOptionList("MeasurementRate", measurementValues, measurementIndex);
            int noiseList       = go.AddOptionList("NoiseCompression", noiseValues, noiseIndex);

            while (true)
            {
                // perform the get operation. This will prompt the user to input a point, but also
                // allow for command line options defined above
                Rhino.Input.GetResult get_rc = go.Get();
                Rhino.RhinoApp.WriteLine(get_rc.ToString());

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

                if (get_rc == Rhino.Input.GetResult.Nothing)
                {
                    //doc.Objects.AddPoint(go.Point());
                    doc.Views.Redraw();
                    Rhino.RhinoApp.WriteLine("Command line option values are");
                    Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue);
                    Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue);
                    Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue);
                    Rhino.RhinoApp.WriteLine(" Measurement rate = {0}", measurementValues[measurementIndex]);
                    Rhino.RhinoApp.WriteLine(" Resolution = {0}", resolutionValues[resolutionIndex]);
                }
                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (go.OptionIndex() == resolutionList)
                    {
                        resolutionIndex = go.Option().CurrentListOptionIndex;
                    }
                    else if (go.OptionIndex() == measurementList)
                    {
                        measurementIndex = go.Option().CurrentListOptionIndex;
                    }

                    continue;
                }
                break;
            }

            return(Rhino.Commands.Result.Success);
        }
Exemplo n.º 3
0
        protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
        {
            var dirname = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string[] pathComponent = new string[] { dirname.ToString(), @"common_paper_sizes.json" };
            var      jsonPath      = Path.Combine(pathComponent);

            GetPoint gp   = new GetPoint();
            string   text = System.IO.File.ReadAllText(jsonPath);

            gp.SetCommandPrompt("Set Origin of Paper Rectangle");

            OptionToggle boolOption = new OptionToggle(false, "Off", "On");

            gp.AddOptionToggle("Portrait", ref boolOption);

            var listNames  = new List <string>();
            var listValues = new List <Point2d>();



            List <Paper> papers = JsonConvert.DeserializeObject <List <Paper> >(text);
            //foreach(var paper in papers)
            //{
            var count = 0;

            foreach (var format in papers[0].formats)
            {
                var num = int.Parse(Regex.Match(format.name, @"\d+").Value);

                if (num < 6 && !format.name.Contains("C"))
                {
                    listNames.Add(format.name);
                    listValues.Add(new Point2d(format.size.mm[0], format.size.mm[1]));
                    count++;
                }
            }

            //}
            var listNamesArr = listNames.ToArray();
            int listIndex    = 0;
            int opList       = gp.AddOptionList("PaperType", listNamesArr, listIndex);

            while (true)
            {
                // perform the get operation. This will prompt the user to input a point, but also
                // allow for command line options defined above
                Rhino.Input.GetResult get_rc = gp.Get();
                if (gp.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(gp.CommandResult());
                }

                if (get_rc == Rhino.Input.GetResult.Point)
                {
                    var plane = doc.Views.ActiveView.ActiveViewport.GetConstructionPlane().Plane;
                    plane.Origin = gp.Point();
                    var item       = listValues[listIndex];
                    var isPortrait = boolOption.CurrentValue;
                    var rect       = new Rectangle3d(plane, isPortrait ? item.X : item.Y, isPortrait ? item.Y : item.X);
                    var attr       = new Rhino.DocObjects.ObjectAttributes();
                    attr.Name       = listNames[listIndex];
                    attr.LayerIndex = doc.Layers.CurrentLayerIndex;
                    doc.Objects.AddRectangle(rect, attr);
                    doc.Views.Redraw();
                }
                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (gp.OptionIndex() == opList)
                    {
                        listIndex = gp.Option().CurrentListOptionIndex;
                    }
                    continue;
                }
                break;
            }
            return(Rhino.Commands.Result.Success);
        }
Exemplo n.º 4
0
        public static GeometryLarge CreateGeometry(MaterialType mType, string mName)

        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;

            //Allow user to pick multiple objects
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Curve;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()
            {
                GeometryFilter              = geometryFilter,
                GroupSelect                 = true,
                SubObjectSelect             = false,
                DeselectAllBeforePostSelect = false
            };
            go.SetCommandPrompt("Pick one or two closed curves.");
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);

            bool bHavePreselectedObjects = false;

            for (;;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }
                break;
            }

            //Unselects the preselected objects
            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();
            }

            ObjRef[]     objs           = go.Objects();
            List <Curve> selectedCurves = new List <Curve>();

            foreach (ObjRef objRef in objs)
            {
                if (objRef.Curve() == null)
                {
                    RhinoApp.WriteLine("One of the selected objects was invalid.");
                    continue;
                }
                else if (!objRef.Curve().IsClosed)
                {
                    RhinoApp.WriteLine("One of the selected curves was not closed.");
                    continue;
                }
                selectedCurves.Add(objRef.Curve());
            }

            GeometryLarge larg;

            //if the curve is not closed do nothing
            switch (selectedCurves.Count)
            {
            case 0:
                Rhino.RhinoApp.WriteLine("No valid geometries was found.");
                return(null);

            case 1:
                larg = DrawAndSaveUserAttr(Brep.CreatePlanarBreps(selectedCurves)[0], doc, mType, mName);
                break;

            case 2:
                Brep brep1 = Brep.CreatePlanarBreps(new[] { selectedCurves[0] })[0];
                Brep brep2 = Brep.CreatePlanarBreps(new[] { selectedCurves[1] })[0];

                double area      = Brep.CreateBooleanUnion(new[] { brep1, brep2 }, 0.001)[0].GetArea();
                double brep1Area = brep1.GetArea();
                double brep2Area = brep2.GetArea();
                if (area > 0.999 * brep1Area && area < 1.001 * brep1Area)
                {
                    Brep brep = Brep.CreateBooleanDifference(brep1, brep2, doc.ModelAbsoluteTolerance)[0];
                    larg = DrawAndSaveUserAttr(brep, doc, mType, mName);
                    break;
                }

                else if (area > 0.999 * brep2Area && area < 1.001 * brep2Area)
                {
                    Brep brep = Brep.CreateBooleanDifference(brep1, brep2, doc.ModelAbsoluteTolerance)[0];
                    larg = DrawAndSaveUserAttr(brep, doc, mType, mName);
                    break;
                }
                else
                {
                    RhinoApp.WriteLine("The curves were not inside one another.");
                    return(null);
                }

            default:
                return(null);
            }

            foreach (ObjRef objRef in objs)
            {
                doc.Objects.Delete(objRef, false);
            }
            return(larg);
        }
Exemplo n.º 5
0
        //Creates reinforcement objects and saves them into the selected point as userData
        public static Reinforcement[] CreateReinforcements(string mName, double diam)
        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;

            //Allow user to pick multiple objects
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject()
            {
                GeometryFilter              = geometryFilter,
                GroupSelect                 = true,
                SubObjectSelect             = false,
                DeselectAllBeforePostSelect = false
            };
            go.SetCommandPrompt("Pick all the points that you want to change to reinforcement.");
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);

            bool bHavePreselectedObjects = false;

            for (;;)
            {
                Rhino.Input.GetResult res = go.GetMultiple(1, 0);
                if (go.ObjectsWerePreselected)
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false, true);
                    continue;
                }
                break;
            }

            //Unselects the preselected objects
            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 layerIndex = GetOrCreateLayer(doc, "Reinforcement", Color.Black);

            if (layerIndex == 999)
            {
                return new Reinforcement[] {}
            }
            ;


            Reinforcement[] reinfList = { };
            //Create reinforcement objects for each selected points
            ObjRef[] objects = go.Objects();
            if (objects != null)
            {
                reinfList = CreateReinfObjs(doc, objects, layerIndex, mName, diam);
            }



            return(reinfList);
        }
Exemplo n.º 6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point;

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Pick all the points that you want to change to reinforcement.");
            go.GeometryFilter  = geometryFilter;
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;

            bool bHavePreselectedObjects = false;

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

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

            List <Point3d> points = new List <Point3d>();

            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 layerIndex = getLayerIndex(doc, "Reinforcement");

            doc.Layers[layerIndex].Color = Color.Black;
            if (layerIndex == 999)
            {
                return(Result.Failure);
            }

            ObjRef[] objects = go.Objects();
            foreach (ObjRef obj in objects)
            {
                Point3d point = obj.Point().Location;

                //TODO add the functionality how to assign different steel materials.
                Reinforcement reinf = new Reinforcement
                {
                    Material  = new SteelMaterial("B500B"),
                    BasePoint = point,
                    Diameter  = 8
                };



                ObjectAttributes attr = new ObjectAttributes();
                attr.UserData.Add(reinf);
                attr.SetUserString("Name", "Reinforcement");
                attr.LayerIndex = layerIndex;

                //Unused code to create a hatch around the point

                /*
                 * doc.Objects.AddCurve(reinf.OutLine,attr);
                 * ObjectAttributes attrHatch = new ObjectAttributes();
                 * attrHatch.LayerIndex = layerIndex;
                 * doc.Objects.AddHatch(reinf.Hatch, attrHatch);
                 */


                doc.Objects.ModifyAttributes(obj, attr, true);
            }



            return(Result.Success);
        }
Exemplo n.º 7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.ApplicationSettings.HistorySettings.RecordingEnabled = true;
            double tolerance = doc.ModelAbsoluteTolerance;

            GetObject gc = new GetObject();

            gc.SetCommandPrompt("Select curve(s) for multipipe");
            gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
            gc.GroupSelect    = true;
            gc.GetMultiple(1, 0);

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

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

            for (int i = 0; i < gc.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = gc.Object(i);
                Rhino.Geometry.Curve    curve  = objref.Curve();
                curves.Add(curve);
                ids.Add(objref.ObjectId);
            }


            Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
            gn.SetCommandPrompt("Start and end radius");
            int opList = gn.AddOptionList("Cap", caps, capIndex);

            gn.SetDefaultNumber(radius1);

            while (true)
            {
                Rhino.Input.GetResult get_rc = gn.Get();
                if (gn.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(gn.CommandResult());
                }

                if (get_rc == Rhino.Input.GetResult.Number)
                {
                    radius1 = gn.Number();
                    if (radius1 < 0 || radius1 < 0.0)
                    {
                        Dialogs.ShowMessage("Value must be >= 0.0", "Warning!");
                        continue;
                    }
                }


                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (gn.OptionIndex() == opList)
                    {
                        capIndex = gn.Option().CurrentListOptionIndex;
                    }
                    continue;
                }

                break;
            }



            while (true)
            {
                RhinoGet.GetNumber("Middle radius", false, ref radius2);
                if (radius2 <= 0 || radius2 <= 0.0)
                {
                    Dialogs.ShowMessage("Value must be > 0.0", "Warning!");
                    continue;
                }

                break;
            }



            Brep[] pipe;

            double[]      radiParam = { 0.0, 0.5, 1.0 };
            double[]      radi      = { radius1, radius2, radius1 };
            PipeCapMode[] pCapM     = { PipeCapMode.None, PipeCapMode.Flat, PipeCapMode.Round };

            // Create a history record
            Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, HISTORY_VERSION);
            WriteHistory(history, ids, radius1, radius2, capIndex);

            foreach (Curve x in curves)
            {
                pipe = Brep.CreatePipe(x, radiParam, radi, true, pCapM[capIndex], true, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceRadians);
                doc.Objects.AddBrep(pipe[0], null, history, false);
                doc.Views.Redraw();
            }


            doc.Views.Redraw();
            return(Result.Success);
        }