典型的深度克隆操作 
以下代码摘录显示了 的典型用法。AcDbDatabase::deepCloneObjects() 启动深度克隆操作
 在此示例中,所有者对象 ID 是模型空间块表记录。该函数填充对象 ID 映射 ()。然后,应用程序可以使用特殊的迭代器对象 () 循环访问映射中包含的对象,并对这些对象执行其他操作,例如按特定矩阵转换每个对象。deepCloneObjects()idMapAcDbIdMappingIter 以下代码显示了deepCloneObjects(): void
cloneSameOwnerObjects()
{
    // Step 1:  Obtain the set of objects to be cloned.
    ads_name sset;
    if (acedSSGet(NULL, NULL, NULL, NULL, sset) != RTNORM) {
        acutPrintf("\nNothing selected");
        return;
    }
    // Step 2: Add obtained object IDs to list of objects
    // to be cloned.
    long length;
    acedSSLength(sset, &length);
    AcDbObjectIdArray  objList;
    AcDbObjectId ownerId = AcDbObjectId::kNull;
    for (int i = 0; i < length; i++) {
        ads_name ent;
        acedSSName(sset, 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)
            objList.append(objId);
        else if (i == 0) {
            ownerId = pObj->ownerId();
            objList.append(objId);
        }
        pObj->close();
    }
    acedSSFree(sset);
    // Step 3: Get the object ID of the desired owner for
    // the cloned objects.  We'll use model space for
    // this example.
    //
    AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);
    AcDbObjectId  modelSpaceId;
    pBlockTable->getAt(ACDB_MODEL_SPACE, modelSpaceId);
    pBlockTable->close();
    // Step 4:  Create a new ID map.
    //
    AcDbIdMapping idMap;
    // Step 5: Call deepCloneObjects().
    //
    acdbHostApplicationServices()->workingDatabase()
        ->deepCloneObjects(objList, modelSpaceId, 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-11-4 15:15
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.