插入外部文件中的块到当前文档
我在网上看见的一段代码,目的是插入外部文件的块,我测试之后发现有异常,CAD命令行提示“块 b43000 参照本身" //文中的mDoc、mDb为当前活动文档的
public void InsertBlock ( )
{
using (Database blkDb = new Database(false, true))
{
blkDb. ReadDwgFile("c:\\a.dwg", System. IO. FileShare. Read, true, null);
blkDb. CloseInput(true);
using (DocumentLock docLock = mDoc. LockDocument( ))
{
using (Transaction tr = mDoc. TransactionManager. StartTransaction( ))
{
ObjectId idBtr = mDb. Insert("b43000", blkDb, false);//执行到这里的时候出现异常:eSelfReference
BlockTable bt = (BlockTable) tr. GetObject(mDb. BlockTableId, OpenMode. ForRead);
BlockTableRecord btr = (BlockTableRecord) tr. GetObject(
bt , OpenMode.ForWrite);
using (BlockReference bref = new BlockReference(new Point3d(0, 0, 0), idBtr))
{
btr. AppendEntity(bref);
tr. AddNewlyCreatedDBObject(bref, true);
}
tr. Commit( );
}
}
}
}
页:
[1]