Hi @rsodre, unfortunately as explained in my previous post, your GeDialog the one that hosts your BaseLink as its not part of the cloned document is not updated by the AliasTrans, during the GetClone operation.
so a quick workaround is to store this BaseLink in the BaseContainer of the document and then retrieve it (Kudo to @m_magalhaes for the idea).
Then there are two issues in your code, first, you never initialize the ailiasTrans, and you don't pass the flag COPYFLAGS::DOCUMENT while you are copying a document.
And here a code sample that demonstrates the use of a BaseContainer.
BaseObject* const obj = doc->GetActiveObject();
if (obj == nullptr || !obj->IsInstanceOf(Ocube))
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
doc->SetName("Original"_s);
// Build the BaseLink
AutoAlloc<BaseLink> nodeLink;
if (!nodeLink)
return maxon::NullptrError(MAXON_SOURCE_LOCATION);
nodeLink->SetLink(obj);
// Store it in GeData
GeData baseLinkData;
baseLinkData.SetBaseLink(*nodeLink);
// Store the GeData in the document, I use the ID 1000000 but please use anunique ID from plugincafe
doc->GetDataInstance()->SetData(1000000, baseLinkData);
// Copy the document, dont forget to initialize the AliasTrans
AutoAlloc<AliasTrans> aliastrans;
aliastrans->Init(doc);
BaseDocument* newDoc = static_cast<BaseDocument*>( doc->GetClone( COPYFLAGS::DOCUMENT, aliastrans ) );
newDoc->SetName("Copy"_s);
aliastrans->Translate( true );
// Read the GeData in the document
const GeData baseLinkDataNewDoc = newDoc->GetDataInstance()->GetData(1000000);
BaseLink* baseLinkNewDoc = baseLinkDataNewDoc.GetBaseLink();
if (baseLinkNewDoc == nullptr)
return maxon::NullptrError(MAXON_SOURCE_LOCATION);
BaseList2D* test = baseLinkNewDoc->GetLink(newDoc);
if (test == nullptr)
return maxon::NullptrError(MAXON_SOURCE_LOCATION);
ApplicationOutput("@, @"_s, test->GetName(), test->GetDocument()->GetName());
test = baseLinkNewDoc->ForceGetLink();
if (test == nullptr)
return maxon::NullptrError(MAXON_SOURCE_LOCATION):
ApplicationOutput("@, @"_s, test->GetName(), test->GetDocument()->GetName());
return maxon::OK;
}
Cheers,
Maxime.