组是维护数据库实体的有序集合的容器对象。可以将组视为命名的持久选择集。它们没有指向它们所包含的实体的所有权链接。 擦除实体后,会自动将其从包含该实体的组中删除。如果实体未擦除,则会自动将其重新插入到组中。 使用该函数获取迭代器并单步执行组中的实体。Theclass 还提供了以下功能:将实体追加和预置到组、在组中的特定索引处插入实体、删除实体以及将实体从组中的一个位置转移到另一个位置。查看ObjectARX 引用。AcDbGroup::newIterator()AcDbGroupAcDbGroup 您还可以使用 theclass 的 ,,,, 和函数将属性分配给组的所有成员。这些操作与打开组中的每个实体并直接设置其属性具有相同的效果。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-1-8 19:35
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.