以下代码展示如何遍历 AutoCAD 文档中的组。
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBDictionary groups = tr.GetObject(db.GroupDictionaryId,
OpenMode.ForRead) as DBDictionary;
// 遍历所有的组
foreach (DBDictionaryEntry entry in groups)
{
Group group = tr.GetObject(entry.Value, OpenMode.ForRead) as Group;
ObjectId[] ids = group.GetAllEntityIds();
// 遍历组下的图元
foreach (ObjectId oid in ids)
{
Entity entity = tr.GetObject(oid, OpenMode.ForRead) as Entity;
}
doc.Editor.WriteMessage("Group: {0} 包含 {1} 个图元\n", group.Name, ids.Length);
}
tr.Commit();
}
版权声明:本文为hisinwang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。