ObjectARX, AutoCAD. Среда программирования библиотеки C++



         

Группы и Словарь Группы - часть 2


->getGroupDictionary(pGroupDict, AcDb::kForWrite);

AcDbObjectId groupId;

pGroupDict->setAt("ASDK_GROUPTEST", pGroup, groupId);

pGroupDict->close();

pGroup->close();

makeGroup(groupId);

removeAllButLines(groupId);

}

// Prompts the user to select objects to add to the group,

// opens the group identified by "groupId" passed in as

// an argument, then adds the selected objects to the group.

//

void

makeGroup(AcDbObjectId groupId)

{

ads_name sset;

int err = acedSSGet(NULL, NULL, NULL, NULL, sset);

if (err != RTNORM) {

return;

}

AcDbGroup *pGroup;

acdbOpenObject(pGroup, groupId, AcDb::kForWrite);

// Traverse the selection set, exchanging each ads_name

// for an object ID, then adding the object to the group.

//

long i, length;

ads_name ename;

AcDbObjectId entId;

acedSSLength(sset, &length);

for (i = 0; i < length; i++) {

acedSSName(sset, i, ename);

acdbGetObjectId(entId, ename);

pGroup->append(entId);

}

pGroup->close();

acedSSFree(sset);

}

// Accepts an object ID of an AcDbGroup object, opens it,

// then iterates over the group, removing all entities that

// are not AcDbLines and changing all remaining entities in

// the group to color red.

//

void

removeAllButLines(AcDbObjectId groupId)

{

AcDbGroup *pGroup;

acdbOpenObject(pGroup, groupId, AcDb::kForWrite);

AcDbGroupIterator *pIter = pGroup->newIterator();

AcDbObject *pObj;

for (; !pIter->done(); pIter->next()) {

pIter->getObject(pObj, AcDb::kForRead);

// If it is not a line or descended from a line,

// close it and remove it from the group. Otherwise,

// just close it.

//

if (!pObj->isKindOf(AcDbLine::desc())) {

// AcDbGroup::remove() requires that the object

// to be removed be closed, so close it now.

//

pObj->close();

pGroup->remove(pIter->objectId());

} else {

pObj->close();

}

}

delete pIter;

// Now change the color of all the entities in the group

// to red (AutoCAD color index number 1).

//

pGroup->setColorIndex(1);

pGroup->close();

}




Содержание  Назад  Вперед