/// <summary>
        /// 获取某图层下所有多边型元素
        /// </summary>
        public static void GetAllShapeByLayer()
        {
            try
            {
                ShapesDefine shape = new ShapesDefine();
                ObjectId[]   objs  = GetAllShape();

                if (objs == null)
                {
                    return;
                }

                foreach (ObjectId objId in objs)
                {
                    //某个元素
                    //Entity ent = (Entity)trans.GetObject(objId, OpenMode.ForWrite);
                    var ent = objId.ToCADShape(true);

                    string pl = ent.Type.ToString();
                    //判断是否为多边型元素
                    if (pl.Contains("Polyline"))// && ent.Points.Count() == 22)
                    {
                        //CADShape sp = new CADShape();
                        // sp.AddPoints(ent as Polyline, true);

                        //add by qclei 2020-04-29 判断是否是封闭的图形
                        //bool bl = PulicGadget.ifColseShape(sp);
                        //if (bl)
                        {
                            //ent.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByBlock, 3); ;

                            //获取图层的名称
                            string name1 = PulicGadget.getShapeName(ent);
                            if (name1 != "")
                            {
                                ent.Name = name1;
                            }
                            shape.addShape(ent);
                        }
                    }
                }

                if (shape.shapelist.Count() > 0)
                {
                    string xml = shape.toXml();
                    MyTool.TextReport("GetAllShapeByLayer", xml, 700, 500);
                }
            }
            catch (Autodesk.AutoCAD.BoundaryRepresentation.Exception ex)
            {
                string exm = ex.Message;
                MyTool.TextReport("GetAllShapeByLayer 出错:", exm, 700, 500);
            }

            return;
        }
예제 #2
0
        public static void GetShapeInfo()
        {
            var id = Interaction.GetEntity("Select:");
            var sp = id.ToCADShape(true);

            //add by qclei 2020-04-29 判断是否是封闭的图形
            //bool bl = PulicGadget.ifColseShape(sp);
            //if (bl)
            {
                string name = PulicGadget.getShapeName(sp);
                if (name != "")
                {
                    sp.Name = name;
                }
                var xml = sp.ToXml();

                MyTool.TextReport("ShapeInfo", xml, 700, 500);
            }
        }
        /// <summary>
        /// 手动获取多个“多边型”图形
        /// </summary>
        public static void GetAllShapeByManual()
        {
            ShapesDefine shape = new ShapesDefine();

            int iCount = 1;

            while (true)
            {
                string sel = string.Format("Select {0} :", iCount.ToString());
                var    id  = Interaction.GetEntity(sel);

                if (id.Handle.Value != 0)
                {
                    var sp = id.ToCADShape(true);

                    //add by qclei 2020-04-29 判断是否是封闭的图形
                    //bool bl = PulicGadget.ifColseShape(sp);
                    //if (bl)
                    {
                        string name = PulicGadget.getShapeName(sp);
                        if (name != "")
                        {
                            sp.Name = name;
                        }
                        shape.addShape(sp);
                        iCount++;
                    }
                }
                else
                {
                    break;
                }
            }

            if (shape.shapelist.Count() > 0)
            {
                string xml = shape.toXml();
                MyTool.TextReport("ShapeInfos", xml, 700, 500);
            }
        }
        private static ShapesDefine GetParkLayerByName(string name, bool getNewName)
        {
            ShapesDefine shape = new ShapesDefine();
            Database     db    = HostApplicationServices.WorkingDatabase;
            Editor       ed    = Interaction.ActiveEditor;// Application.DocumentManager.MdiActiveDocument.Editor;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead, false);

                foreach (ObjectId lid in lt)
                {
                    LayerTableRecord lt1 = (LayerTableRecord)trans.GetObject(lid, OpenMode.ForRead, false);

                    string lName = lt1.Name;

                    if (lName.Contains(name))
                    {
                        TypedValue[] pTypeValue = new TypedValue[] { new TypedValue((int)DxfCode.LayerName, lName) };

                        SelectionFilter       pSelectFilter = new SelectionFilter(pTypeValue);
                        PromptSelectionResult pSelectResult = ed.SelectAll(pSelectFilter);
                        SelectionSet          pSelectSet    = pSelectResult.Value;

                        if (pSelectSet != null)
                        {
                            ObjectId[] objs = pSelectSet.GetObjectIds();

                            foreach (ObjectId objId in pSelectSet.GetObjectIds())
                            {
                                //某个元素
                                //Entity ent = (Entity)trans.GetObject(objId, OpenMode.ForRead);
                                var ent = objId.ToCADShape(true);
                                //判断是否为多边型元素
                                string pl = ent.Type.ToString();
                                //判断是否为多边型元素
                                if (pl.Contains("Polyline"))// && ent.Points.Count() == 22)
                                {
                                    ent.Name = lName;
                                    if (getNewName)
                                    {
                                        string name1 = PulicGadget.getShapeName(ent);
                                        if (name1 != "")
                                        {
                                            ent.Name = name1;
                                        }
                                    }


                                    {
                                        //ent.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByBlock, 3); ;

                                        //获取图层的名称
                                        shape.addShape(ent);
                                    }
                                }
                            }
                        }
                    }
                }

                trans.Commit();
            }

            return(shape);
        }