Published date: 2005-02-08
ID: TS27355
Applies to:
AutoCAD® 2005
Issue
How do I remove anonymous groups from my drawing using ObjectARX?
Solution
When an end user creates a 'group' in AutoCAD, it may be an anynonmus group.
However, all group (anonymous or otherwise) are stored in the Named Objects Dictionary under the key 'ACAD_GROUP'.
If the group is anonymous, AutoCAD assigns it a value such as '*A1', '*A2' and so on.
Although to the end user it's anonymous, the goup has a unique key name in the AutoCAD database.
Users may add or remove entities from groups so it is possible to have empty groups.
To remove an anonyomus group, consider the following code fragment - rmvAnonGrp().
Before running the code given below, creat few unnamed groups(anonymous groups).
ObjectARX contains a function getGroupsDictionary() that returns a pointer to the GROUPS dictionary at the ACAD_GROUP key.
The GROUPS dictionary conatains AcDbGroup objects.
To step through the GROUPS dictionary, use the services of a dictionary interator, pDictIter.
Attach the interator to the GROUPS dictionary using pDictIter = pGroupDict->newIterator().
Within a for loop, step through all the AcDbGroup objects.
If the group is not an anonymous group, simply skip to another interation of the for loop.
The pGroup->isAnonymous() returns True if the AcDbGroup is anonymous.
If the group is anonymous, and there are any entities in the anonymous group, upgrade the status of the AcDbGroup from read to write and
clear() all the entities out of the group.
Then remove the group from the GROUPS dictionary using pGroupDict->remove(groupId).
Be sure to close the AcDbGroup objects and AcDbDictionary when you are finished with them.
ID: TS27355
Applies to:
AutoCAD® 2005
Issue
How do I remove anonymous groups from my drawing using ObjectARX?
Solution
When an end user creates a 'group' in AutoCAD, it may be an anynonmus group.
However, all group (anonymous or otherwise) are stored in the Named Objects Dictionary under the key 'ACAD_GROUP'.
If the group is anonymous, AutoCAD assigns it a value such as '*A1', '*A2' and so on.
Although to the end user it's anonymous, the goup has a unique key name in the AutoCAD database.
Users may add or remove entities from groups so it is possible to have empty groups.
To remove an anonyomus group, consider the following code fragment - rmvAnonGrp().
Before running the code given below, creat few unnamed groups(anonymous groups).
// Remove anonymous groups.
// Note: No error cheking in following code
void rmvAnonGrps()
{
// TODO: Implement the command
Acad::ErrorStatus es;
AcDbDictionary *pGroupDict;
AcDbGroup *pGroup;
AcDbDictionaryIterator *pDictIter;
AcDbObjectId groupId;
long numItems;
AcDbObjectIdArray groupMembers;
es =
acdbHostApplicationServices()->workingDatabase()->getGroupDictionary(pGroupDict,
AcDb::kForWrite);
// If using R14 then use the following instead.
// es = acdbCurDwg()->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();
}
The GROUP dictionary is contained in the Named Objects Dictionary, however,ObjectARX contains a function getGroupsDictionary() that returns a pointer to the GROUPS dictionary at the ACAD_GROUP key.
The GROUPS dictionary conatains AcDbGroup objects.
To step through the GROUPS dictionary, use the services of a dictionary interator, pDictIter.
Attach the interator to the GROUPS dictionary using pDictIter = pGroupDict->newIterator().
Within a for loop, step through all the AcDbGroup objects.
If the group is not an anonymous group, simply skip to another interation of the for loop.
The pGroup->isAnonymous() returns True if the AcDbGroup is anonymous.
If the group is anonymous, and there are any entities in the anonymous group, upgrade the status of the AcDbGroup from read to write and
clear() all the entities out of the group.
Then remove the group from the GROUPS dictionary using pGroupDict->remove(groupId).
Be sure to close the AcDbGroup objects and AcDbDictionary when you are finished with them.
댓글
댓글 쓰기