如果要从不同的所有者克隆一组对象,则需要将这组对象 ID 划分为每个所有者的单独组。(克隆的对象及其所有者应属于同一数据库。在本节的示例中,将添加要克隆的模型空间对象,并将要克隆的图纸空间对象添加到:objListMSobjListPS objListMS.append(objId); objListPS.append(objId); 然后使用相同的 ID 映射调用该函数两次。必须使用单个 ID 映射进行所有克隆,以便正确完成参考翻译。在第一次调用时,参数设置为 。在第二次(最后一次)调用时,默认为:deepCloneObjects()deferXlationkTruedeepCloneObjects()deferXlationkFalse acdbHostApplicationServices()->workingDatabase()-> deepCloneObjects(mslist, modelSpaceId, idMap, Adesk::kTrue); acdbHostApplicationServices()->workingDatabase()-> deepCloneObjects(pslist, paperSpaceId, idMap); 此时,克隆结束,所有参考文献都已翻译。以下代码深层克隆属于不同所有者的对象: void cloneDiffOwnerObjects() { // Step 1: Obtain the set of objects to be cloned. // For the two owners we'll use model space and // paper space, so we must perform two acedSSGet() calls. // calls. // acutPrintf("\nSelect entities to be cloned to" " Model Space"); ads_name ssetMS; acedSSGet(NULL, NULL, NULL, NULL, ssetMS); long lengthMS; acedSSLength(ssetMS, &lengthMS); acutPrintf("\nSelect entities to be cloned to" " Paper Space"); ads_name ssetPS; if (acedSSGet(NULL, NULL, NULL, NULL, ssetPS) != RTNORM && lengthMS == 0) { acutPrintf("\nNothing selected"); return; } long lengthPS; acedSSLength(ssetPS, &lengthPS); // Step 2: Add obtained object IDs to the lists of // objects to be cloned: one list for objects to // be owned by model space and one for those to // be owned by paper space. AcDbObjectId ownerId = AcDbObjectId::kNull; // For model space // AcDbObjectIdArray objListMS; for (int i = 0; i < lengthMS; i++) { ads_name ent; acedSSName(ssetMS, i, ent); AcDbObjectId objId; acdbGetObjectId(objId, ent); // Check to be sure this has the same owner as the first // object. // AcDbObject *pObj; acdbOpenObject(pObj, objId, AcDb::kForRead); if (pObj->ownerId() == ownerId) objListMS.append(objId); else if (i == 0) { ownerId = pObj->ownerId(); objListMS.append(objId); } pObj->close(); } acedSSFree(ssetMS); // For paper space // ownerId = AcDbObjectId::kNull; AcDbObjectIdArray objListPS; for (i = 0; i < lengthPS; i++) { ads_name ent; acedSSName(ssetPS, i, ent); AcDbObjectId objId; acdbGetObjectId(objId, ent); // Check to be sure this has the same owner as the first // object. // AcDbObject *pObj; acdbOpenObject(pObj, objId, AcDb::kForRead); if (pObj->ownerId() == ownerId) objListPS.append(objId); else if (i == 0) { ownerId = pObj->ownerId(); objListPS.append(objId); } pObj->close(); } acedSSFree(ssetPS); // Step 3: Get the object ID of the desired owners for // the cloned objects. We're using model space and // paper space for this example. // AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbObjectId modelSpaceId, paperSpaceId; pBlockTable->getAt(ACDB_MODEL_SPACE, modelSpaceId); pBlockTable->getAt(ACDB_PAPER_SPACE, paperSpaceId); pBlockTable->close(); // Step 4: Create a new ID map. // AcDbIdMapping idMap; // Step 5: Call deepCloneObjects(). // acdbHostApplicationServices()->workingDatabase() ->deepCloneObjects(objListMS, modelSpaceId, idMap, Adesk::kTrue); acdbHostApplicationServices()->workingDatabase() ->deepCloneObjects(objListPS, paperSpaceId, idMap); // Now we can go through the ID map and do whatever we'd // like to the original and/or clone objects. // // For this example we'll print out the object IDs of // the new objects resulting from the cloning process. // AcDbIdMappingIter iter(idMap); for (iter.start(); !iter.done(); iter.next()) { AcDbIdPair idPair; iter.getMap(idPair); if (!idPair.isCloned()) continue; acutPrintf("\nObjectId is: %Ld", idPair.value().asOldId()); } } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:42
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.