3
我在编写一个方法,提示用户选择所有要合并到一个块中的实体,然后将它们连接在一起并返回块参考。现在看起来像这样。使用C#以编程方式将AutoCAD实体连接到块中
/// <summary>
/// Returns all entities in an AutoCAD drawing in a list
/// </summary>
public static List<Entity> GetEntitiesInDrawing()
{
List<Entity> entitiesToReturn = new List<Entity>(); //Blocks that will be returned
Transaction tr = _database.TransactionManager.StartTransaction();
DocumentLock docLock = _activeDocument.LockDocument();
using (tr)
using (docLock)
{
BlockTableRecord blockTableRecord = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(_database), OpenMode.ForRead);
foreach (ObjectId id in blockTableRecord)
{
try
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
entitiesToReturn.Add(ent);
}
catch (InvalidCastException)
{
continue;
}
}
}
return entitiesToReturn;
}
/// <summary>
/// Prompts the user for a number of entities and then joins them into a block
/// </summary>
public static BlockReference JoinEntities()
{
BlockReference blkToReturn = null;
List<Entity> entitiesToJoin = PromptUserForEntities();
foreach (Entity ent in entitiesToJoin)
{
// ToDo: Join entities into blkToReturn
}
return blkToReturn;
}
我的问题是,我不知道如何或者如果有可能采取实体列表并将它们加入到blockreference中。
我遵循的程序和现在它每次尝试追加一个实体给它时抛出一个eAlreadyInDb错误新的BTR。你可以在这里看到我的完整代码http://forums.autodesk.com/t5/net/joining-entities-into-a-block-programmatically/mp/5651349/highlight/false#M44682#4 –
这是预期的:你不能附加和实体到2块表记录...看到我上面的建议,#3,尝试与AssumeOwnershipOf 也块表记录不能包含实体,直到已经在数据库中...所以先添加BTR,然后将实体移动到它。 –