[MSCE C++]请问如何给元素添加外部文件links

请问右击元素给元素添加links如何通过代码实现?比如给元素添加一个外部文件link,谢谢老师。

Parents
  • 如下MSCE C++代码测试通过(为简单起见,未增加任何多余的容错代码):

    	ElementHandle eh(2656L, ACTIVEMODEL);
    	DgnLinkTreeSpecPtr spec = DgnLinkManager::CreateTreeSpec(eh);
    	DgnLinkTreePtr linkTree = DgnLinkManager::ReadLinkTree(*spec, true);
    	DgnLinkTreeBranchR root = linkTree->GetRootR();
    
    	StatusInt status;
    	auto leaf = DgnLinkManager::CreateLink(status, DGNLINK_TYPEKEY_File);
    	DgnDocumentMonikerPtr moniker = DgnDocumentMoniker::CreateFromFileName(L"C:\\111\\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);



    Answer Verified By: Zemin.Li 

Reply
  • 如下MSCE C++代码测试通过(为简单起见,未增加任何多余的容错代码):

    	ElementHandle eh(2656L, ACTIVEMODEL);
    	DgnLinkTreeSpecPtr spec = DgnLinkManager::CreateTreeSpec(eh);
    	DgnLinkTreePtr linkTree = DgnLinkManager::ReadLinkTree(*spec, true);
    	DgnLinkTreeBranchR root = linkTree->GetRootR();
    
    	StatusInt status;
    	auto leaf = DgnLinkManager::CreateLink(status, DGNLINK_TYPEKEY_File);
    	DgnDocumentMonikerPtr moniker = DgnDocumentMoniker::CreateFromFileName(L"C:\\111\\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);



    Answer Verified By: Zemin.Li 

Children