Example #1
0
        public static List <Guid> Guids(ObjectType filter)
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一个或多个,之后回车确认");
                go.GeometryFilter = filter;
                if (go.GetMultiple(1, 0) != GetResult.Object)
                {
                    return(null);
                }

                List <Guid> ghCurveList1 = new List <Guid>();
                Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(obj.ObjectId));
                if (ghCurveList1.Count == 0)
                {
                    return(null);
                }
                return(ghCurveList1);
            }
        }
Example #2
0
        public static List <Curve> Curves()
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一条或多条曲线,之后回车或者右键确认");
                go.GeometryFilter = ObjectType.Curve | ObjectType.EdgeFilter;

                if (go.GetMultiple(1, 0) != GetResult.Object)
                {
                    return(null);
                }

                List <Curve> ghCurveList1 = new List <Curve>();
                Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(obj.Curve()));
                if (ghCurveList1.Count == 0)
                {
                    return(null);
                }
                return(ghCurveList1);
            }
        }
Example #3
0
        public static List <GH_Point> PickPoint()
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一个或多个,之后回车确认");
                go.GeometryFilter = ObjectType.Point;

                if (go.GetMultiple(1, 0) != GetResult.Object)
                {
                    return(null);
                }

                List <GH_Point> ghCurveList1 = new List <GH_Point>();
                Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(new GH_Point(obj.Point().Location)));
                if (ghCurveList1.Count == 0)
                {
                    return(null);
                }
                return(ghCurveList1);
            }
        }
Example #4
0
        public static List <T> Pick <T>(ObjectType filter, string message)
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt(message);
                go.GeometryFilter = filter;

                if (go.GetMultiple(1, 0) != GetResult.Object)
                {
                    return(null);
                }

                List <T> list = new List <T>();
                Array.ForEach(go.Objects(), (ObjRef obj) =>
                {
                    dynamic geo;
                    if (typeof(T).Name == "GH_Point")
                    {
                        geo = obj.Point().Location;
                    }
                    else if (typeof(T).Name == "GH_Curve")
                    {
                        geo = obj.Curve();
                    }
                    else
                    {
                        geo = null;
                    }

                    if (geo != null)
                    {
                        list.Add(geo);
                    }
                });

                if (list.Count == 0)
                {
                    return(null);
                }
                return(list);
            }
        }
Example #5
0
        public static Point3d Point()
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一条点物件,之后回车或者右键确认");
                go.GeometryFilter = ObjectType.Point;

                if (go.Get() != GetResult.Object)
                {
                    return(Point3d.Unset);
                }

                var obj = go.Object(0);
                return(obj.Point().Location);
            }
        }
Example #6
0
        public static Guid Guid(ObjectType filter)
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一个物件,之后回车确认");
                go.GeometryFilter = filter;

                if (go.Get() != GetResult.Object)
                {
                    return(System.Guid.Empty);
                }

                var obj = go.Object(0);
                return(obj.ObjectId);
            }
        }
Example #7
0
        public static Curve Curve()
        {
            GetObject go;

            while (true)
            {
                go = new GetObject();
                go.AcceptNothing(true);
                go.AcceptEnterWhenDone(true);
                go.SetCommandPrompt("请选择一条曲线,之后回车或者右键确认");
                go.GeometryFilter = ObjectType.Curve | ObjectType.EdgeFilter;

                if (go.Get() != GetResult.Object)
                {
                    return(null);
                }

                var obj = go.Object(0);
                var crv = obj.Curve();
                return(crv);
            }
        }
Example #8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go;

            go = new GetObject();
            go.AcceptNothing(true);
            go.AcceptEnterWhenDone(true);
            go.SetCommandPrompt("请选择边界");
            go.GeometryFilter = ObjectType.Curve;

            if (go.Get() != GetResult.Object)
            {
                return(Result.Failure);
            }
            Curve boundCrv = go.Object(0).Curve();

            if (!boundCrv.IsPlanar() || !boundCrv.IsPolyline() || !boundCrv.IsClosed)
            {
                return(Result.Failure);
            }

            boundCrv.GetBoundingBox(Plane.WorldXY, out Box bound);

            var dialog = new SelectFolderDialog()
            {
                Title = "保存位置"
            };

            DialogResult res = dialog.ShowDialog(Rhino.UI.RhinoEtoApp.MainWindow);

            if (res == DialogResult.Ok)
            {
                try
                {
                    Dictionary <string, string> pathMap = new Dictionary <string, string>();

                    foreach (var layer in doc.Layers)
                    {
                        var objects = doc.Objects.FindByLayer(layer);
                        if (!layer.IsVisible || !layer.IsValid || objects.Length == 0)
                        {
                            continue;
                        }

                        string name = layer.FullPath.Replace(Layer.PathSeparator, "$$");

                        string realPath = IOPath.Combine(dialog.Directory, name + ".eps");
                        string tmpPath  = IOPath.Combine(IOPath.GetTempPath(), layer.Id.ToString());

                        var eps = new EncapsulatedPostScript(bound);

                        var objs = SelectAllObjectsInBound(bound, objects);
                        if (objs.Count == 0)
                        {
                            continue;
                        }

                        eps.SaveEPS(objs, tmpPath);

                        pathMap.Add(tmpPath, realPath);
                    }

                    if (pathMap.Count == 0)
                    {
                        return(Result.Cancel);
                    }

                    foreach (KeyValuePair <string, string> item in pathMap)
                    {
                        System.IO.File.Move(item.Key, item.Value);
                        RhinoApp.WriteLine($"已写入, {item.Value}");
                    }

                    System.Diagnostics.Process.Start(dialog.Directory);
                }
                catch (Exception ex)
                {
                    RhinoApp.WriteLine(ex.Message);
                } finally
                {
                    doc.Objects.UnselectAll();
                    doc.Views.Redraw();
                }
            }

            return(Result.Success);
        }