Thanks to a tip from Yongan.Fu we know how to add (attach) a DgnLink to an element...
DgnLinkTreeSpecPtr spec = DgnLinkManager::CreateTreeSpec(eh); const bool CreateIfUnavailable {true}; DgnLinkTreePtr linkTree = DgnLinkManager::ReadLinkTree(*spec, CreateIfUnavailable); DgnLinkTreeBranchR root = linkTree->GetRootR(); StatusInt status; auto leaf = DgnLinkManager::CreateLink(status, DGNLINK_TYPEKEY_File); DgnDocumentMonikerPtr moniker = DgnDocumentMoniker::CreateFromFileName(L"C:\\temp\\test.dgn"); DgnLinkP link = leaf->GetLinkP(); DgnFileLinkP fileLink = dynamic_cast<DgnFileLinkP>(link); fileLink->SetMoniker(moniker.get(), true); WString name = link->BuildSuggestedName(&root, true); WString uniqueName = root.GetUniqueChildName(name.GetWCharCP()); leaf->SetName(uniqueName.GetWCharCP()); root.AddChild(*leaf, 0); DgnLinkManager::WriteLinkTree(*linkTree);
The code creates a new DgnLink as a DgnLinkTreeLeaf
. The penultimate line adds a new leaf to a DgnLinkTreeBranch
, and the last line persists the tree.
Now I want to — terminology alert — detach/delete/drop/remove a DgnLink. DgnLinkManager
doesn't have such a method, but DgnLinkTreeBranch
does have a DropChild
method. Presumably we examine a DgnLink branch to find a particular child, drop it and then rewrite the DgnLinkTreeBranch
. Have I deduced the correct way to delete a DgnLink, or is there a better way?