示例#1
0
        public static void SaveSelection()
        {
            var ids = Interaction.GetPickSet();

            if (ids.Length == 0)
            {
                Interaction.WriteLine("No entity selected.");
                return;
            }
            string name = Interaction.GetString("\nSelection name");

            if (name == null)
            {
                return;
            }
            if (CustomDictionary.GetValue("Selections", name) != string.Empty)
            {
                Interaction.WriteLine("Selection with the same name already exists.");
                return;
            }
            var    handles   = ids.QSelect(x => x.Handle.Value.ToString()).ToArray();
            string dictValue = string.Join("|", handles);

            CustomDictionary.SetValue("Selections", name, dictValue);
        }
示例#2
0
文件: Interaction.cs 项目: iamHXQ/Oy
        /// <summary>
        /// 多个实体,输入编号逐个查看
        /// </summary>
        /// <param name="ids">实体ID数组</param>
        /// <param name="action">动作</param>
        public static void ZoomHighlightView(List <ObjectId> ids, Action <int> action = null) // newly 20130815
        {
            if (ids.Count > 0)
            {
                List <ObjectId> highlightIds = new List <ObjectId>();
                while (true)
                {
                    string input = Interaction.GetString("\n输入编号查看,按回车退出");
                    if (input == null)
                    {
                        break;
                    }
                    var index = Convert.ToInt32(input);
                    if (index <= 0 || index > ids.Count)
                    {
                        Interaction.WriteLine("编号不在范围内。");
                        continue;
                    }

                    if (action != null)
                    {
                        action(index);
                    }
                    highlightIds.Clear();
                    highlightIds.Add(ids[index - 1]);
                    Interaction.ZoomObjects(highlightIds);
                    Interaction.HighlightObjects(highlightIds);
                }
            }
        }
示例#3
0
        public static void GetPoint2()
        {
            var p = Interaction.GetPoint("Point");

            Interaction.WriteLine("P1(Original):" + p.ToString());
            MyTool.ShowWCSAndUCS(p);
        }
示例#4
0
        public static void DetectSelfIntersection() // mod 20130202
        {
            ObjectId[]    ids   = QuickSelection.SelectAll("LWPOLYLINE").ToArray();
            ProgressMeter meter = new ProgressMeter();

            meter.Start("Detecting...");
            meter.SetLimit(ids.Length);
            var results = ids.QWhere(x =>
            {
                bool result = (x as Polyline).IsSelfIntersecting();
                meter.MeterProgress();
                System.Windows.Forms.Application.DoEvents();
                return(result);
            }).ToList();

            meter.Stop();
            if (results.Count() > 0)
            {
                Interaction.WriteLine("{0} detected.", results.Count());
                Interaction.ZoomHighlightView(results);
            }
            else
            {
                Interaction.WriteLine("0 detected.");
            }
        }
示例#5
0
        public static void PolyClean3()
        {
            double value = Interaction.GetValue("\nNumber of segs to fit an arc, 0 for smart determination", 0);

            if (double.IsNaN(value))
            {
                return;
            }
            int n = (int)value;

            ObjectId[] ids       = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            var        entsToAdd = new List <Polyline>();

            ids.QForEach <Polyline>(poly =>
            {
                var pts     = poly.GetPolylineFitPoints(n);
                var poly1   = NoDraw.Pline(pts);
                poly1.Layer = poly.Layer;
                try
                {
                    poly1.ConstantWidth = poly.ConstantWidth;
                }
                catch
                {
                }
                poly1.XData = poly.XData;
                poly.Erase();
                entsToAdd.Add(poly1);
            });
            entsToAdd.ToArray().AddToCurrentSpace();
            Interaction.WriteLine("{0} handled.", entsToAdd.Count);
        }
示例#6
0
        public static void PolyClean4()
        {
            double value = Interaction.GetValue("\nDirection:1-R to L;2-B to T;3-L to R;4-T to B");

            if (double.IsNaN(value))
            {
                return;
            }
            int n = (int)value;

            if (!new int[] { 1, 2, 3, 4 }.Contains(n))
            {
                return;
            }
            Algorithms.Direction dir = (Algorithms.Direction)n;

            ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            int        m   = 0;

            ids.QForEach <Polyline>(poly =>
            {
                m += Algorithms.PolyClean_SetTopoDirection(poly, dir);
            });
            Interaction.WriteLine("{0} handled.", m);
        }
示例#7
0
        public static void PolyClean2()
        {
            double epsilon = Interaction.GetValue("\nEpsilon", _polyClean2Epsilon);

            if (double.IsNaN(epsilon))
            {
                return;
            }
            _polyClean2Epsilon = epsilon;

            ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            int        m   = 0;
            int        n   = 0;

            ids.QForEach <Polyline>(poly =>
            {
                int count = Algorithms.PolyClean_ReducePoints(poly, epsilon);
                if (count > 0)
                {
                    m++;
                    n += count;
                }
            });
            Interaction.WriteLine("{1} vertex removed from {0} polyline.", m, n);
        }
示例#8
0
 public static void GetColumnPointsEx()
 {
     try
     {
         CADAreaList areaList = new CADAreaList();
         var         zero     = Interaction.GetPoint("ZeroPoint");
         string[]    keys     = { "0:左下", "1:右下", "2:右上", "3:左上" };
         string      p1       = zero.ToString();
         string      p2       = zero.ToUCS().ToString();
         string      p3       = zero.ToWCS().ToString();
         Interaction.WriteLine(string.Format("\n zero [{0},{1},{2}]", p1, p2, p3));
         var key = Interaction.GetKeywords("\nChoose1 Zero Type ", keys);
         if (string.IsNullOrEmpty(key))
         {
             return;
         }
         //var key = Interaction.GetKeywords("\nChoose1 Zero Type ", keys);
         var columns = Interaction.GetEntitysByLayers("COLUMN");
         var area    = columns.ToCADArea(zero.ToCADPoint(true), key, true, true);
         area.Name = "主厂房0m层";
         areaList.Add(area);
         var txt = areaList.ToXml();
         MyTool.TextReport("Points", txt, 700, 500);
     }
     catch (System.Exception ex)
     {
         MyTool.TextReport("Exception", ex.ToString(), 700, 500);
     }
 }
示例#9
0
        public void TestKeywords()
        {
            string[] keys = { "A", "B", "C", "D" };
            var      key  = Interaction.GetKewords("\nChoose an option", keys, 3);

            Interaction.WriteLine("You chose {0}.", key);
        }
示例#10
0
文件: Test.cs 项目: iamHXQ/Oy
        public static void PolyClean3()
        {
            double value = Interaction.GetValue("\n距离,默认为2", 2);

            if (double.IsNaN(value))
            {
                return;
            }
            double n = value;

            ObjectId[] ids       = Interaction.GetSelection("\n选择多段线", "LWPOLYLINE");
            var        entsToAdd = new List <Polyline>();

            ids.QForEach <Polyline>(poly =>
            {
                var pts     = poly.GetPolylineDivPoints(n);
                var poly1   = NoDraw.Pline(pts);
                poly1.Layer = poly.Layer;
                try
                {
                    poly1.ConstantWidth = poly.ConstantWidth;
                }
                catch
                {
                }
                poly1.XData = poly.XData;
                poly.Erase();
                entsToAdd.Add(poly1);
            });
            entsToAdd.ToArray().AddToCurrentSpace();
            Interaction.WriteLine("{0} handled.", entsToAdd.Count);
        }
示例#11
0
        public void TestUngroup()
        {
            ObjectId[] ids = Interaction.GetSelection("\nSelect entities");
            Modify.Ungroup(ids);
            DBDictionary groupDict = HostApplicationServices.WorkingDatabase.GroupDictionaryId.QOpenForRead <DBDictionary>();

            Interaction.WriteLine("{0} groups.", groupDict.Count);
        }
示例#12
0
        public static void GetLineOfPoint()
        {
            var p = Interaction.GetPoint("GetLineOfPoint");

            Interaction.WriteLine(p.ToString());
            var p2 = Interaction.GetLineEndPoint("otherPoint", p);

            Interaction.WriteLine(p2.ToString());
        }
示例#13
0
 public static void PolyClean5()
 {
     Interaction.WriteLine("Not implemented yet");
     ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
     ids.QForEach <Polyline>(poly =>
     {
         Algorithms.PolyClean_RemoveColinearPoints(poly);
     });
 }
示例#14
0
        public void TestSelection()
        {
            Point3d  point = Interaction.GetPoint("\nPoint");
            double   value = Interaction.GetDistance("\nSize");
            Vector3d size  = new Vector3d(value, value, 0);

            ObjectId[] ids = Interaction.GetWindowSelection(point - size, point + size);
            Interaction.WriteLine("{0} entities selected.", ids.Count());
        }
示例#15
0
 public void TestTaskDialog()
 {
     if (Interaction.TaskDialog("请选择。", "吃饭", "睡觉", "懒人选择", "你必须做出选择", "你只有这些选择", "没有其他选项") == true)
     {
         Interaction.WriteLine("就知道吃!");
     }
     else
     {
         Interaction.WriteLine("就知道睡!");
     }
 }
示例#16
0
        public static void ShowPoints()
        {
            var p1 = Interaction.GetPoint("坐标1");
            var p2 = Interaction.GetPoint("坐标2");

            Interaction.WriteLine(string.Format("({0} {1})", p1, p2));
            PointInfo pi1 = GetRoomsCommand.GetPointInfo(p1);
            PointInfo pi2 = GetRoomsCommand.GetPointInfo(p2);

            Interaction.WriteLine(string.Format("({0} {1})", pi1, pi2));
        }
示例#17
0
 public void TestCustomDictionary()
 {
     CustomDictionary.SetValue("dict1", "A", "apple");
     CustomDictionary.SetValue("dict1", "B", "orange");
     CustomDictionary.SetValue("dict1", "A", "banana");
     CustomDictionary.SetValue("dict2", "A", "peach");
     foreach (var dict in CustomDictionary.GetDictionaryNames())
     {
         Interaction.WriteLine(dict);
     }
     Interaction.WriteLine(CustomDictionary.GetValue("dict1", "A"));
 }
示例#18
0
        public static void PolyClean0()
        {
            ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            int        n   = 0;

            ids.QForEach <Polyline>(poly =>
            {
                if (poly.Length == 0)
                {
                    poly.Erase();
                    n++;
                }
            });
            Interaction.WriteLine("{0} eliminated.", n);
        }
示例#19
0
        public static void PolyClean()
        {
            ObjectId[] ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            int        m   = 0;
            int        n   = 0;

            ids.QForEach <Polyline>(poly =>
            {
                int count = Algorithms.PolyClean_RemoveDuplicatedVertex(poly);
                if (count > 0)
                {
                    m++;
                    n += count;
                }
            });
            Interaction.WriteLine("{1} vertex removed from {0} polyline.", m, n);
        }
示例#20
0
        public static void PolySplit()
        {
            ObjectId[]      ids      = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
            List <Polyline> newPolys = new List <Polyline>();
            ProgressMeter   pm       = new ProgressMeter();

            pm.Start("Processing...");
            pm.SetLimit(ids.Length);
            ids.QOpenForWrite <Polyline>(list =>
            {
                foreach (var poly in list)
                {
                    Point3dCollection intersectPoints = new Point3dCollection();
                    foreach (var poly1 in list)
                    {
                        if (poly1 != poly)
                        {
                            poly.IntersectWith3264(poly1, Intersect.OnBothOperands, intersectPoints);
                        }
                    }
                    var ipParams = intersectPoints.Cast <Point3d>().Select(ip => poly.GetParamAtPointX(ip)).OrderBy(param => param).ToArray();
                    if (intersectPoints.Count > 0)
                    {
                        var curves = poly.GetSplitCurves(new DoubleCollection(ipParams));
                        foreach (var curve in curves)
                        {
                            newPolys.Add(curve as Polyline);
                        }
                    }
                    else // mod 20130227 不管有无交点,都要添加到newPolys,否则孤立线将消失。
                    {
                        newPolys.Add(poly.Clone() as Polyline);
                    }
                    pm.MeterProgress();
                }
            });
            pm.Stop();
            if (newPolys.Count > 0)
            {
                newPolys.ToArray().AddToCurrentSpace();
                ids.QForEach(x => x.Erase());
            }
            Interaction.WriteLine("Broke {0} to {1}.", ids.Length, newPolys.Count);
        }
示例#21
0
        private static TopoInfo GetFloor()
        {
            string txt = Interaction.GetString("输入楼层名称");

            if (string.IsNullOrEmpty(txt))
            {
                txt = "楼层1";
            }

            var       p1  = Interaction.GetPoint("楼层坐标1");
            PointInfo pi1 = GetPointInfo(p1);

            var       p2  = Interaction.GetPoint("楼层坐标2");
            PointInfo pi2 = GetPointInfo(p2);

            TopoInfo topoInfo = GetTopoInfo(txt, AreaTypes.楼层, pi1, pi2);

            Interaction.WriteLine(string.Format("{0} {1} {2}\n", pi1, pi2, txt));
            //Interaction.WriteLine("");
            return(topoInfo);
        }
示例#22
0
        public static void PolyLanding()
        {
            ObjectId[]      ids            = QuickSelection.SelectAll("*LINE,ARC").ToArray();
            List <ObjectId> landingLineIds = new List <ObjectId>();

            while (true)
            {
                Point3d p = Interaction.GetPoint("\nSpecify a point");
                if (p.IsNull())
                {
                    break;
                }
                Point3d[] landings = ids.QSelect(x => (x as Curve).GetClosestPointTo(p, false)).ToArray();
                double    minDist  = landings.Min(x => x.DistanceTo(p));
                Point3d   landing  = landings.First(x => x.DistanceTo(p) == minDist);
                Interaction.WriteLine("Shortest landing distance of point ({0:0.00},{1:0.00}) is {2:0.00}。", p.X, p.Y, minDist);
                ObjectId landingLineId = Draw.Line(p, landing);
                landingLineIds.Add(landingLineId);
            }
            landingLineIds.QForEach(x => x.Erase());
        }
示例#23
0
        private static TopoInfo GetFloorEx()
        {
            string txt = Interaction.GetString("输入楼层名称");

            if (string.IsNullOrEmpty(txt))
            {
                txt = "楼层1";
            }

            int pCout            = 0;
            List <PointInfo> pis = new List <PointInfo>();

            while (true)
            {
                pCout++;
                var p1 = Interaction.GetPoint("楼层坐标" + pCout);
                if (double.IsNaN(p1.X))
                {
                    if (pis.Count >= 2)
                    {
                        break; //出口
                    }
                    else
                    {
                        continue;
                    }
                }
                PointInfo pi1 = GetPointInfo(p1);
                pis.Add(pi1);
            }

            //var p2 = Interaction.GetPoint("楼层坐标2");
            //PointInfo pi2 = GetPointInfo(p2);

            TopoInfo topoInfo = GetTopoInfo(txt, AreaTypes.楼层, pis);

            Interaction.WriteLine(string.Format("{0} {1} {2}\n", pis.First(), pis.Last(), txt));
            //Interaction.WriteLine("");
            return(topoInfo);
        }
示例#24
0
        private static TopoInfo GetRoom()
        {
            roomCount++;

            var p1 = Interaction.GetPoint("房间坐标1");

            if (double.IsNaN(p1.X))
            {
                return(null);                   //这里是出口
            }
            var p2 = Interaction.GetPoint("房间坐标2");

            if (double.IsNaN(p2.X))
            {
                return(null);                   //这里是出口
            }
            string room = GetText(p1, p2);

            if (string.IsNullOrEmpty(room))
            {
                room = Interaction.GetString("输入房间名称");
                if (string.IsNullOrEmpty(room))
                {
                    room = "房间_" + roomCount;
                }
            }

            PointInfo pi1      = GetPointInfo(p1);
            PointInfo pi2      = GetPointInfo(p2);
            TopoInfo  topoInfo = GetTopoInfo(room, AreaTypes.机房, pi1, pi2);

            Interaction.WriteLine(string.Format("{0} {1} {2}", pi1, pi2, room));
            Interaction.WriteLine("");

            //string xml = XmlSerializeHelper.GetXmlText(topoInfo);
            //Gui.TextReport("房间:" + txt, xml, 700, 500);

            return(topoInfo);
        }
示例#25
0
        public static void PolylineInfo() // mod by WY 20130202
        {
            ObjectId id = Interaction.GetEntity("\nSpecify a polyline", typeof(Polyline));

            if (id == ObjectId.Null)
            {
                return;
            }
            Polyline poly = id.QOpenForRead <Polyline>();

            for (int i = 0; i <= poly.EndParam; i++)
            {
                Interaction.WriteLine("[Point {0}] coord: {1}; bulge: {2}", i, poly.GetPointAtParameter(i), poly.GetBulgeAt(i));
            }
            List <ObjectId> txtIds = new List <ObjectId>();
            double          height = poly.GeometricExtents.MaxPoint.DistanceTo(poly.GeometricExtents.MinPoint) / 50.0;

            for (int i = 0; i < poly.NumberOfVertices; i++)
            {
                txtIds.Add(Draw.MText(i.ToString(), height, poly.GetPointAtParameter(i), 0, true));
            }
            Interaction.GetString("\nPress ENTER to exit");
            txtIds.QForEach(x => x.Erase());
        }
示例#26
0
        private static TopoInfo GetRoomEx()
        {
            roomCount++;

            int              pCout = 0;
            List <Point3d>   ps    = new List <Point3d>();
            List <PointInfo> pis   = new List <PointInfo>();
            double           pMinX = double.MaxValue;
            double           pMinY = double.MaxValue;
            double           pMaxX = double.MinValue;
            double           pMaxY = double.MinValue;

            int     ibegin    = 0;
            Point3d lineBegin = new Point3d();

            while (true)
            {
                pCout++;
                var p1 = Interaction.GetPoint("房间坐标" + pCout);
                if (double.IsNaN(p1.X))
                {
                    if (pis.Count >= 2)
                    {
                        break; //出口
                    }
                    else
                    {
                        continue;
                    }
                }
                ps.Add(p1);
                PointInfo pi1 = GetPointInfo(p1);

                if (ibegin == 0)
                {
                    lineBegin = p1;
                    ibegin    = 1;
                }
                else
                {
                    var leftLine = Draw.Line(lineBegin, p1);
                    lineBegin = p1;
                    // leftLine.SetLayer("aaa");

                    leftLine.QOpenForWrite <Entity>(line => line.ColorIndex = 3);
                    var arrow = Modify.Group(new[] { leftLine });
                }

                pis.Add(pi1);

                if (p1.X < pMinX)
                {
                    pMinX = p1.X;
                }
                if (p1.Y < pMinY)
                {
                    pMinY = p1.Y;
                }

                if (p1.Y > pMaxY)
                {
                    pMaxY = p1.Y;
                }
                if (p1.X > pMaxX)
                {
                    pMaxX = p1.X;
                }
            }

            Point3d pMin = Point3d.Origin;
            Point3d pMax = Point3d.Origin;

            if (pis.Count == 2)
            {
                pMin = ps[0];
                pMax = ps[1];
            }
            else
            {
                pMin = new Point3d(pMinX, pMinY, 0);
                pMax = new Point3d(pMaxX, pMaxY, 0);
            }

            string room = GetText(pMin, pMax);

            if (string.IsNullOrEmpty(room))
            {
                room = Interaction.GetString("输入房间名称");
                if (string.IsNullOrEmpty(room))
                {
                    room = "房间_" + roomCount;
                }
            }

            TopoInfo topoInfo = GetTopoInfo(room, AreaTypes.机房, pis);

            Interaction.WriteLine(string.Format("{0} {1} {2}", pis.First(), pis.Last(), room));
            Interaction.WriteLine("");

            //string xml = XmlSerializeHelper.GetXmlText(topoInfo);
            //Gui.TextReport("房间:" + txt, xml, 700, 500);

            return(topoInfo);
        }
示例#27
0
        public static void GetAnchors()
        {
            try
            {
                var zero = Interaction.GetPoint("选择原点");
                //string[] keys = { "1F", "2F", "3F", "4F" };
                //var key = Interaction.GetKeywords("\n选择楼层", keys);
                var          anchorObjects = Interaction.GetEntitysByLayers("-人员定位");
                CADShapeList sps           = new CADShapeList();
                for (int i = 0; i < anchorObjects.Length; i++)
                {
                    ObjectId item = anchorObjects[i];
                    var      sp   = item.ToCADShape(true);
                    sps.Add(sp);
                    Interaction.WriteLine(string.Format("{0}({1}/{2})", sp, i + 1, anchorObjects.Length));
                }

                var types = sps.GetTypesEx();

                string typesText = "";
                foreach (var item in types)
                {
                    typesText += item.Key + ",";
                }

                Interaction.Write("Types:" + typesText);

                //var circleList = types["Circle"];
                //var zeroCircle = circleList[0];
                //var zeroP = zeroCircle.GetPoint();

                var pZero = zero.ToCADPoint(false);//获取的坐标原本就是用户坐标系的
                foreach (CADShape sp in sps)
                {
                    sp.SetZero(pZero);
                }

                CADShapeList anchorList = new CADShapeList();
                if (types.ContainsKey("BlockReference"))
                {
                    anchorList = types["BlockReference"];
                }

                CADShapeList textList = new CADShapeList();
                if (types.ContainsKey("MText"))
                {
                    textList.AddRange(types["MText"]);
                }
                if (types.ContainsKey("DBText"))
                {
                    textList.AddRange(types["DBText"]);
                }

                CADAnchorList result = new CADAnchorList();


                List <string> names       = new List <string>();
                CADShapeList  usedText    = new CADShapeList();
                string        repeatNames = "";
                for (int i = 0; i < anchorList.Count; i++)
                {
                    var anchor = anchorList[i];
                    var text   = textList.FindCloset(anchor);
                    if (text != null)
                    {
                        //if (text.Text.Contains(key))
                        {
                            anchor.Text = text.Text;
                            anchor.Name = text.Text;
                            result.Anchors.Add(anchor);

                            if (!names.Contains(anchor.Name))
                            {
                                names.Add(anchor.Name);
                            }
                            else
                            {
                                repeatNames += anchor.Name + ";";
                            }
                            usedText.Add(text);
                        }
                    }
                }

                string noUseNames = "";
                foreach (var item in textList)
                {
                    if (!usedText.Contains(item))
                    {
                        noUseNames += item.Text + ";";
                    }
                }


                result.Anchors.Sort();
                for (int i = 0; i < result.Anchors.Count; i++)
                {
                    result.Anchors[i].Num = i + 1;
                }

                if (repeatNames != "")
                {
                    MyTool.TextReport("重复基站", repeatNames, 700, 500);
                }

                if (noUseNames != "")
                {
                    MyTool.TextReport("遗漏基站", noUseNames, 700, 500);
                }

                var txt = result.ToXml();
                MyTool.TextReport("Anchors", txt, 700, 500);
            }
            catch (System.Exception ex)
            {
                MyTool.TextReport("Exception", ex.ToString(), 700, 500);
            }
        }
示例#28
0
        public static void GetUCS()
        {
            var ucs = MyTool.GetUCS();

            Interaction.WriteLine("Origin:" + ucs.Origin);
        }