向大家请教一个问题,我想遍历图纸空间和模型空间,按照一定的条件找出一些entity
下面是我写的代码,发现得到的layout信息并不是读入的dwg文件对应的,不知道是为什么?
在QQ群里呼叫多次,没有解决
- Database mDatabase = new Database();
- try
- {
- mDatabase.ReadDwgFile(filename, System.IO.FileShare.Read, true, null);
- using (Transaction tr = mDatabase.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tr.GetObject(mDatabase.BlockTableId, OpenMode.ForRead, false);
- printdata = printdataList.AddFileToPrint(filename);
- foreach (ObjectId btrId in bt)
- {
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
- if (btr.IsLayout) //layoutsToPlot.Add(btId);
- {
- Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);
- LayoutData layoutData = new LayoutData();
- layoutData.LayoutName = lo.LayoutName;
- foreach (ObjectId item in btr)
- {
- Entity ent = tr.GetObject(item, OpenMode.ForRead) as Entity;
- if (!EntityIsTuKuang(ent)) continue;
- Polyline pl = ent as Polyline;
- Extents3d ext3D = pl.GeometricExtents;
- Extents2d ext2D = new Extents2d(ext3D.MinPoint.X, ext3D.MinPoint.Y, ext3D.MaxPoint.X, ext3D.MaxPoint.Y);
- layoutData.WinowAreas.Add(PublicMethod.Ext2DToRange(ext2D));
- }
- if (layoutData.WinowAreas.Count != 0)
- printdata.AddLayoutData(layoutData);
- }
- }
- }
- dgvAddRow(printdata);
- }
|