我正在尝试编写一个方法,提示用户选择他们想要组合成块的所有实体,然后将它们连接成一个块并返回块引用。现在它看起来像这样。
/// <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;
}
我的问题是我不知道如何或是否有可能获取实体列表并将它们连接到块引用中。
答案 0 :(得分:4)
基恩在他的博客中提到了这一点:Creating an AutoCAD block using .NET
答案 1 :(得分:2)
总结:
提到的帖子可以提供帮助,但它会创建新实体(并且不会从模型转移到块定义(步骤#3)