コード例 #1
0
        /// <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
        /// <summary>
        /// 根据“大楼”名称获取相应的图层
        /// </summary>
        public static void GetParkBuild(string buildName)
        {
            ShapesDefine shape = new ShapesDefine();

            shape = GetParkLayerByName(buildName, false);

            if (shape.shapelist.Count() > 0)
            {
                string xml = shape.toXml();
                MyTool.TextReport("GetParkBuild", xml, 700, 500);
            }
        }
コード例 #3
0
        /// <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);
            }
        }