public static Result PrePostPick(RhinoDoc doc)
    {
        var go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects");
        go.EnablePreSelect(true, true);
        go.EnablePostSelect(true);
        go.GetMultiple(0, 0);
        if (go.CommandResult() != Result.Success)
          return go.CommandResult();

        var selected_objects = go.Objects().ToList();

        if (go.ObjectsWerePreselected)
        {
          go.EnablePreSelect(false, true);
          go.DeselectAllBeforePostSelect = false;
          go.EnableUnselectObjectsOnExit(false);
          go.GetMultiple(0, 0);
          if (go.CommandResult() == Result.Success)
          {
        foreach (var obj in go.Objects())
        {
          selected_objects.Add(obj);
          // The normal behavior of commands is that when they finish,
          // objects that were pre-selected remain selected and objects
          // that were post-selected will not be selected. Because we
          // potentially could have both, we'll try to do something
          // consistent and make sure post-selected objects also stay selected
          obj.Object().Select(true);
        }
          }
        }
        return selected_objects.Count > 0 ? Result.Success : Result.Nothing;
    }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("CenterPoints");

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

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

            //Compute center and add point to doc

            for (int i = 0; i < go.ObjectCount; i++)
            {
                Guid pointG;
                Rhino.DocObjects.ObjRef      objref = go.Object(i);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                var objType = obj.ObjectType;
                if (objType == Rhino.DocObjects.ObjectType.Curve)
                {
                    Curve  curve  = objref.Curve();
                    Circle circle = new Circle();
                    if (!curve.TryGetCircle(out circle, doc.ModelAbsoluteTolerance))
                    {
                        BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                        Point3d     bbObjCenter = bbObj.Center;
                        pointG = doc.Objects.AddPoint(bbObjCenter);
                    }
                    else
                    {
                        Point3d circleCenter = circle.Center;
                        pointG = doc.Objects.AddPoint(circleCenter);
                    }
                }
                else
                {
                    BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                    Point3d     bbObjCenter = bbObj.Center;
                    pointG = doc.Objects.AddPoint(bbObjCenter);
                }
                Rhino.DocObjects.RhinoObject circObj = doc.Objects.Find(pointG);
                circObj.Attributes.LayerIndex = layerCheck.Index;
                circObj.CommitChanges();
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
Exemple #3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var layerCheck = doc.Layers.FindName("Numbers");

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

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

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

            //Compute center and add point to doc

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

                int a = i + 1;

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

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

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

                int groupIndex = doc.Groups.Count;
                groupIndex++;
                string group = groupIndex.ToString();
                var    gI    = doc.Groups.Add(group);
                doc.Groups.AddToGroup(gI, num);
                doc.Groups.AddToGroup(gI, objGuid);
            }
            doc.Views.Redraw();
            return(Result.Success);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            int currIntOption = 0;
            var gi            = new GetOption();

            gi.SetCommandPrompt("Material Index");
            gi.AcceptNumber(true, true);
            var resgi = gi.Get();

            if (resgi == GetResult.Number)
            {
                currIntOption = Convert.ToInt32(gi.Number());
            }

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to apply material");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);


            //Nothing to do - get out quick.
            if (go.ObjectCount == 0)
            {
                return(Result.Success);
            }

            var rm = FindMaterial(doc, matName[currIntOption]);

            if (null == rm)
            {
                //Didn't find the material - create one and carry on.

                //Create a basic material
                var custom = new Rhino.DocObjects.Material();
                custom.Name = matName[currIntOption];

                if (currIntOption == 13)
                {
                    custom.SetEnvironmentTexture(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Free Jewels Rhino Plug-Ins/Dia3.jpg");
                }
                custom.CommitChanges();

                rm = RenderMaterial.CreateBasicMaterial(custom);
                rm.BeginChange(RenderContent.ChangeContexts.Program);
                rm.SetParameter("diffuse", System.Drawing.Color.Black);
                rm.SetParameter("reflectivity", 1.0);
                rm.SetParameter("reflectivity-color", System.Drawing.Color.FromArgb(r[currIntOption], g[currIntOption], b[currIntOption]));
                rm.SetParameter("transparency", fjMatTrans[currIntOption]);
                rm.SetParameter("shine", fjMatShine[currIntOption]);
                rm.SetParameter("polish-amount", fjMatShine[currIntOption]);
                rm.EndChange();

                var docMats = doc.RenderMaterials;

                docMats.Add(rm);
            }

            //Now we always have a material to assign, this part is easy
            for (int i = 0; i < go.ObjectCount; i++)
            {
                var obj = go.Object(i).Object();

                obj.RenderMaterial = rm;
                obj.CommitChanges();
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
Exemple #7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //pick objects to expand
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to expand");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center
            Point3d centersAdd = new Point3d();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;
                centers.Add(bbObjCenter);
                centersAdd += bbObjCenter;

                Rhino.DocObjects.ObjRef objref = go.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                goList.Add(obj);
            }
            Point3d allCenter = centersAdd / centers.Count;

            //pick center
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Basepoint. Press Enter for automatic.");
            gp.AcceptNothing(true);
            var resgp = gp.Get();

            if (resgp == GetResult.Nothing)
            {
                scaleCenter = allCenter;
            }
            else
            {
                scaleCenter = gp.Point();
            }

            //Expansion factor
            GetPoint gp2 = new GetPoint();

            gp2.SetCommandPrompt("Expansion factor or first reference point <" + factor + ">");
            gp2.DrawLineFromPoint(scaleCenter, true);
            gp2.AcceptNumber(true, true);
            GetResult gr = gp2.Get();

            Rhino.Display.RhinoView view = gp2.View();
            plane2D = view.ActiveViewport.ConstructionPlane();

            if (gr == GetResult.Number)
            {
                factor = gp2.Number();
            }
            if (gr == GetResult.Point)
            {
                scaleRefPoint = gp2.Point();
                Line line1     = new Line(scaleCenter, scaleRefPoint);
                Guid tempLine  = doc.Objects.AddLine(line1);
                Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint);
                if (scaleCenter == gp2.Point())
                {
                    return(Rhino.Commands.Result.Cancel);
                }
                GetPoint gp3 = new GetPoint();
                gp3.SetCommandPrompt("Secondt reference point");
                gp3.AddOptionList("ScaleDimension", dimensions, 0);
                gp3.DrawLineFromPoint(scaleCenter, true);
                gp3.DynamicDraw += RefObjDraw;

                while (true)
                {
                    GetResult res = gp3.Get();
                    if (res == GetResult.Option)
                    {
                        dimensionIndex = gp3.Option().CurrentListOptionIndex;
                        continue;
                    }
                    else if (res == GetResult.Point)
                    {
                        Point3d scaleRefPoint2 = gp3.Point();
                        factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint));
                        doc.Objects.Delete(tempLine, true);
                        doc.Objects.Delete(tempPoint, true);
                    }
                    break;
                }
            }
            RhinoApp.WriteLine("Expantion factor: " + factor);

            //Compute translation

            //Translate 3d
            if (dimensionIndex == 0)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vec   = (centers[i] - scaleCenter) * (factor - 1);
                    var      xform = Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Rhino.Geometry.Vector3d vec = (centers[i] - scaleCenter) * (factor - 1);
                    Vector3d planeNormal        = plane2D.Normal;
                    if (planeNormal[0] != 0)
                    {
                        vec.X = 0;
                    }
                    else if (planeNormal[1] != 0)
                    {
                        vec.Y = 0;
                    }
                    else if (planeNormal[2] != 0)
                    {
                        vec.Z = 0;
                    }
                    var xform = Rhino.Geometry.Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vecEach       = (centers[i] - scaleCenter);
                    double   vecEachLength = vecEach.Length * (factor - 1);
                    Vector3d vec           = (scaleRefPoint - scaleCenter);
                    double   angleVec      = Vector3d.VectorAngle(vecEach, vec);
                    int      pol           = 1;
                    if (angleVec > 1.57)
                    {
                        pol = -1;
                    }
                    vec.Unitize();
                    vec = vec * vecEachLength * pol;

                    var xform = Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }

            goList         = new List <Object>();
            centers        = new List <Point3d>();
            dimensionIndex = 0;
            plane2D        = new Plane();

            doc.Views.Redraw();
            return(Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            List <Rhino.Geometry.Mesh> meshes = new List <Rhino.Geometry.Mesh>();

            try
            {
                string ogre_bin = System.Environment.GetEnvironmentVariable("OGRE_HOME");
#if DEBUG
                ogre_bin += @"\bin\Debug";
#else
                ogre_bin += @"\bin\Release";
#endif

                string path = System.Environment.GetEnvironmentVariable("PATH");
                System.Environment.SetEnvironmentVariable("PATH", path + ";" + ogre_bin,
                                                          EnvironmentVariableTarget.Process);

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

                OptionToggle export_as_xml = new OptionToggle(false, "No", "Yes");
                go.AddOptionToggle("export_as_xml", ref export_as_xml);

                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 (; ;)
                {
                    Rhino.Input.GetResult res = go.GetMultiple(1, 0);

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

                    else if (res != Rhino.Input.GetResult.Object)
                    {
                        RhinoLogger.Info("Canceled.");
                        return(Rhino.Commands.Result.Cancel);
                    }
                    if (go.ObjectsWerePreselected)
                    {
                        bHavePreselectedObjects = true;
                        go.EnablePreSelect(false, true);
                        continue;
                    }

                    break;
                }

                SaveFileDialog sv = new SaveFileDialog();

                if (!export_as_xml.CurrentValue)
                {
                    sv.Filter     = "Mesh files (*.mesh)|*.mesh";
                    sv.DefaultExt = "mesh";
                }
                else
                {
                    sv.Filter     = "XML files (*.xml)|*.xml";
                    sv.DefaultExt = "xml";
                }

                sv.Title = "Select File to Export :";
                if (sv.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    RhinoLogger.Info("Canceled.");
                    return(Result.Cancel);
                }

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

                int objectCount = go.ObjectCount;

                Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount);

                for (int i = 0; i < objectCount; i++)
                {
                    var objref = go.Object(i);
                    if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Mesh)
                    {
                        meshes.Add(objref.Mesh());
                    }
                    else if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Brep)
                    {
                        var ms = CheckOrCreateMesh(objref.Brep(), RhinoDoc.ActiveDoc.GetMeshingParameters(MeshingParameterStyle.Custom));
                        meshes.AddRange(ms);
                    }
                    else
                    {
                        RhinoLogger.ErrorFormat("selection is unexpected ObjectType : {0}", objref.Geometry().ObjectType);
                        return(Result.Failure);
                    }
                }


                var exporter = new ExportToOgreMesh();
                var exp_path = exporter.Export(sv.FileName, meshes);

                if (!export_as_xml.CurrentValue)
                {
                    exporter.ConvertXmlToMesh(exp_path);
                }
            }
            catch (Exception e)
            {
                RhinoLogger.Fatal(e);
                return(Result.Failure);
            }

            return(Result.Success);
        }