示例#1
0
        public void GetAllYDBMGemo(T model, string layerName)
        {
            if (model != null)
            {
                LayerModel lm  = new LayerModel();
                Document   doc = Application.DocumentManager.MdiActiveDocument;
                Database   db  = doc.Database;

                ObjectIdCollection ids = new ObjectIdCollection();
                lm.Name = layerName;

                PromptSelectionResult ProSset = null;
                TypedValue[]          filList = new TypedValue[1] {
                    new TypedValue((int)DxfCode.LayerName, layerName)
                };
                SelectionFilter sfilter = new SelectionFilter(filList);

                ProSset = doc.Editor.SelectAll(sfilter);
                if (ProSset.Status == PromptStatus.OK)
                {
                    using (Transaction tran = db.TransactionManager.StartTransaction())
                    {
                        SelectionSet sst  = ProSset.Value;
                        ObjectId[]   oids = sst.GetObjectIds();

                        LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
                        foreach (ObjectId layerId in lt)
                        {
                            LayerTableRecord ltr = (LayerTableRecord)tran.GetObject(layerId, OpenMode.ForRead);
                            if (ltr.Name == layerName)
                            {
                                lm.Color = System.Drawing.ColorTranslator.ToHtml(ltr.Color.ColorValue);
                            }
                        }

                        foreach (ObjectId lengGemo in oids)
                        {
                            DBObject            ob             = tran.GetObject(lengGemo, OpenMode.ForRead);
                            PointsPlanItemModel pointsPlanItem = new PointsPlanItemModel();
                            if (ob is Polyline)
                            {
                                Polyline aPl = ob as Polyline;
                                // 读取分图则闭合多段线内的用地代码
                                List <PointF> pfs = new List <PointF>();
                                if (aPl.Closed is true)
                                {
                                    int vn2 = aPl.NumberOfVertices;  //lwp已知的多段线
                                    for (int J = 0; J < vn2; J++)
                                    {
                                        Point2d pt = aPl.GetPoint2dAt(J);
                                        PointF  pf = new PointF((float)pt.X, (float)pt.Y);
                                        pfs.Add(pf);
                                    }
                                }
                                pointsPlanItem.Num = MethodCommand.GetAttrIndex(pfs);
                            }

                            BlockInfoModel plModel = MethodCommand.AnalysisBlcokInfo(ob);
                            pointsPlanItem.Geom = plModel;

                            if (lm.modelItemList == null)
                            {
                                lm.modelItemList = new List <object>();
                            }

                            lm.modelItemList.Add(pointsPlanItem);
                        }
                    }

                    if (model.allLines == null)
                    {
                        model.allLines = new List <LayerModel>();
                    }
                    model.allLines.Add(lm);
                }
            }
        }