我经常使用.NET库来获取块引用,但是,我从未使用COM对象获取过块引用。下面的方法是我拥有的一个方法,它将获取块的名称和位置,并返回块引用。我在这里修改了它以接受acadblockreference,并使用它的name属性在blocktable中找到它。我没有时间来测试这个,但我只是想把它扔到这里,希望它能帮助你前进。
很抱歉,我的示例是C,但是在VB.NET中重新编写应该很容易。
public BlockReference GetBlockReferenceFromCOM(AcadBlockReference comReference, Point3d location)
{
using (Database database = Application.DocumentManager.MdiActiveDocument.Database)
{
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
BlockTable blockTable = transaction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRecNewDoc = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockReference newBlockReference = new BlockReference(location, blockTable[comReference.Name]);
transaction.Commit();
return newBlockReference;
}
}
}
编辑
您有这些项目的对象ID吗?如果是这样,您可以这样做:
public DBObject GetBlockReferenceFromCOM(ObjectId id)
{
using (Database database = Application.DocumentManager.MdiActiveDocument.Database)
{
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
return transaction.GetObject(id, OpenMode.ForRead);
}
}
}