组和组词典
组是一个容器对象,用于维护数据库实体的有序集合。组可以看作是命名的持久性选择集。它们没有与它们所包含的实体的所有权链接。 擦除实体后,会自动将其从包含该实体的组中删除。如果实体未擦除,则会自动将其重新插入到组中。 使用该函数获取迭代器并单步执行组中的实体。该类还提供以下函数:将实体追加和预置到组、在组中的特定索引处插入实体、删除实体以及将实体从组中的一个位置转移到另一个位置。请参阅 ObjectARX 参考。AcDbGroup::newIterator()AcDbGroupAcDbGroup 还可以使用类的 、 、 、 和 函数将属性分配给组的所有成员。这些操作与打开组中的每个实体并直接设置其属性具有相同的效果。setColor()setLayer()setLinetype()setVisibility()setHighlight()AcDbGroup 组应始终存储在 GROUP 字典中,可按如下方式获取: AcDbDictionary* pGrpDict =
acdbHostApplicationServices()->working Database()->
getGroupDictionary(pGroupDict, AcDb::kForWrite);
获取 GROUP 字典的另一种方法是在命名对象字典中查找“ACAD_GROUP”。 以下函数是应用程序的一部分,该应用程序首先提示用户选择放置在名为“ASDK_GROUPTEST”的组中的某些实体。然后,它调用该函数以遍历该组并删除所有不是线的实体。最后,它将组中的其余实体更改为红色。removeAllButLines() void groups()
{
AcDbGroup *pGroup = new AcDbGroup("grouptest");
AcDbDictionary *pGroupDict;
acdbHostApplicationServices()->workingDatabase()
->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();
}
注意:在删除其所有迭代器之前,无法关闭 的指针。AcDbGroup
父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 07:06
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.