|
使用 ARX 删除匿名组
当最终用户在 AutoCAD 中创建"组"时,它可能是匿名组。但是,所有组(匿名或其他)都存储在命名对象字典中键"ACAD_GROUP"下。如果该组是匿名的,AutoCAD 会为其分配一个值,例如"*A1"、"*A2"等。尽管对最终用户而言它是匿名的,但该组在 AutoCAD 数据库中具有唯一的键名。
用户可以在组中添加或删除实体,以便可以有空组。下面的代码是一个删除匿名组的小型演示。
[code]static void removeGroup()
{
Acad::ErrorStatus es;
AcDbDictionary *pGroupDict;
AcDbGroup *pGroup;
AcDbDictionaryIterator *pDictIter;
AcDbObjectId groupId;
long numItems;
AcDbObjectIdArray groupMembers;
es =
acdbHostApplicationServices()->workingDatabase()->
getGroupDictionary(pGroupDict,AcDb::kForWrite);
pDictIter = pGroupDict->newIterator();
for(; !pDictIter->done(); pDictIter->next())
{
pDictIter->getObject(
(AcDbObject*&)pGroup, AcDb::kForRead);
// Is the group anonymous?
if(pGroup->isAnonymous())
{
// Does the anonymous group have
// any members associated with it?
numItems = pGroup->numEntities();
if(numItems > 0)
{
// Empty the group
// Upgrade it first
es = pGroup->upgradeOpen();
es = pGroup->clear();
es = pGroup->downgradeOpen();
pGroup->close();
}
// Get the group ID and remove the
// group from the dictionary
groupId = pDictIter->objectId();
es = pGroupDict->remove(groupId);
} // if
pGroup->close();
} // for
pGroupDict->close();
}[/code] |
|