[求助]遍历图纸空间和模型空间
向大家请教一个问题,我想遍历图纸空间和模型空间,按照一定的条件找出一些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);
} <p>打印方面的很少有人弄哈</p>
<p>我是没搞过这东东</p> <p>上面的代码和打印的关系不大</p>
<p> </p>
<p>我需要做的就是,读入一个dwg的数据库,然后遍历所有的图纸空间和模型空间。比如说我现在的dwg有两个layout:“model”,“我的布局”,但是通过以上代码得到却不是这两个layout,很奇怪</p> 同样的代码在当前数据库中却有效果,能够得到想要的值 <p>估计你获取的是当前文档的layout?、</p>
<p>试下设置当前数据库?</p>
<p>HostApplicationServices.WorkingDatabase = mDatabase;</p>
<p>记得做完要还原</p> <font face="Verdana">Database mDatabase = new Database(false,true);</font> OK
页:
[1]