ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Deep Clone custom object with hardOwnership

0 REPLIES 0
Reply
Message 1 of 1
MagdalenaCisowska
128 Views, 0 Replies

Deep Clone custom object with hardOwnership

Hello, I have made custom object, deriving from AcDbEntity. It stores its 'subobjects', as hardOwnershipId:

 

std::vector<AcDbHardOwnershipId> subObjects_;

 

 

I set the subobjects as follows (based on https://help.autodesk.com/view/OARXMAC/2024/ENU/?guid=GUID-157D8BA1-D8B8-4EBE-9B87-C3A8D25DB508) :

 

Acad::ErrorStatus CustomObject::appendObjectSetOwnerId(const AcDbHardOwnershipId& ownedId) {
    assertWriteEnabled();
    if (ownedId.asOldId() == 0L || objectId().asOldId() == 0L) {
        acutPrintf(_T("\nERROR: cannot set ownership because either CustomObject or subObject ID = 0"));
        return Acad::eInvalidInput;
    }
    subObjects_.emplace_back(ownedId);
    // set backpointer
    AcDbObject* pSubObject;
    AcTransaction* pTrans = actrTransactionManager->startTransaction();
    pTrans->getObject(pSubObject, ownedId, AcDb::kForWrite);
    pSubObject->setOwnerId(objectId());
    actrTransactionManager->endTransaction();
    return Acad::eOk;
}

 

 

To make deep clone work, I had to override subDeepClone() method. I used https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-7570C673-9C10-4784-BD0C-86821973C3F5 as the source implementation. Unfortunatelly, deep cloning the subobjects does not work and whole deep clone operation aborts (I made custom reactor deriving from AcEditorReactor and hence I know that it aborts, because abortDeepClone() is invoked).

The problem seems to narrow to the following line:

 

// Open the object and clone it.  Note that we now
// set "isPrimary" to kFalse here because the object
// is being cloned, not as part of the primary set,
// but because it is owned by something in the
// primary set.
//
acdbOpenAcDbObject(pSubObject, id, AcDb::kForRead);
pClonedSubObject = NULL;
pSubObject->deepClone(pClonedObject, //-> here only pOwner works for me and does not abort!
                  pClonedSubObject,
                  idMap, Adesk::kFalse);

 

 

As you can see, subObject should invoke deepClone and pass pClonedObject as its owner, but this causes the whole deep clone to abort. Setting pOwner as the subobject's owner does not abort, but is centainly not correct, as pOwner in this case is BlockTableRecord.

 

Please help me deal with it correctly. Maybe it's something with dwgIn/OutFields?

 

...
pFiler->writeInt32(static_cast<Adesk::Int32>(subObjects_.size()));
for (const auto& objectId : subObjects_) {
    pFiler->writeHardOwnershipId(objectId);
}
...

...
Adesk::Int32 numObjects;
pFiler->readInt32(&numObjects);
for (auto i = 0; i < numObjects; i++) {
    subObjects_.emplace_back();
    auto& objectId = subObjects_.back();
    pFiler->readHardOwnershipId(&objectId);
}

 

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators