Hello everyone,
I'm trying to parse dgn file and update location of it's reference file.
Say I have c:\Main.dgn which has reference c:\refs\Ref1.dgn
And I want it to be moved Ref1.dgn to another location(and maybe name), say c:\notRefs\Ref2.dgn
DGN platform is used for these, not Microstation API, because I don't want Microstation to be launched for this tiny task.
The problem here that I can't update reference location.
File Modified time was changed but reference location remains the same.
Maybe I missed something vital, but I can't get it from the document, nothing there was found.
Thanks,
Artem
So I have the following code (simplified version, removed dozens of checks that pointer is not null and operation returned 0 and so on):
// open & load parent file
auto document = DgnDocument::CreateFromFileName(status, path.c_str(), nullptr, DEFDGNFILE_ID, DgnDocument::FETCH_Write, DgnDocument::FETCH_OPTION_WithSet);
RefCountedPtr<DgnFile> file = DgnFile::Create(*document, DGNFILE_OPENMODE_READWRITE, *DgnRefUpdater::Utils::StaticHostHelper::host);
file->LoadDgnFile(&res);
// Load references from the root model
auto models = file->GetModelIndexCollection();
for (auto it = models.begin(); it != models.end(); ++it)
{
Bentley::StatusInt status_load = 0;
DgnModelP model = file->LoadRootModelById(&status_load, (*it).GetModelId(), true, true, true);
if (status_load == 0)
{
auto currentAttach = model->FindDgnAttachmentByElementId(elementId);
if (currentAttach)
{
// check it's current path
auto saved = currentAttach->GetAttachMoniker()->GetSavedFileName();
// create new moniker
auto mon = Bentley::DgnPlatform::DgnDocumentMoniker::CreateFromFileName(L"C:\\Users\\Artem\\Documents\\Vault\\ABursuk\\Ref1.dgn");
DgnDocumentMonikerR newMon = *mon;
// set new moniker to the reference
currentAttach->SetAttachMoniker(newMon);
// save changes
auto sts = file->ProcessChanges(Bentley::DgnPlatform::DGNSAVE_APPL_INITIATED);
break;
}
}