Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

[CONNECT Update 16.2 C++] Problem creating DgnLink for a URL

$
0
0

Following the examples posted on this Forum, I am experimenting with the DgnLink C++ API.

I can successfully create a File DgnLink and a Folder DgnLink.  For example, this is working code (error-catching omitted) …

template<>
    bool CreateDgnLink<DgnFolderLinkP>  (DgnLinkTreeBranchR root, TempDgnLinkTreeLeafOwner& leaf,  WCharCP    folderPath)
    {
        bool                created       {false};
        int                 status        {-1};
                            leaf          = DgnPlatform::DgnLinkManager::CreateLink(status, DGNLINK_TYPEKEY_Folder);
        if (SUCCESS == status)
        {
            DgnFolderLinkP         folderLink  = dynamic_cast<DgnFolderLinkP>(leaf->GetLinkP());
            DgnFolderMonikerPtr    moniker     {DgnFolderMoniker::CreateFromFolderName(folderPath)};
            folderLink->SetMoniker(*moniker.get());
            const bool             FullContext    {true};
            WString             name           = folderLink->BuildSuggestedName(&root, FullContext);
            WString             uniqueName     = root.GetUniqueChildName(name.GetWCharCP());
            leaf->SetName(uniqueName.GetWCharCP());
            created = true;
        }

        return created;
    }

That's added to a link tree like this …

bool  AddLeafToTree (EditElementHandleR eeh, DgnLinkTreePtr& linkTree, TempDgnLinkTreeLeafOwner& leaf, size_t index) const
{
    DgnLinkTreeBranchR            root        = linkTree->GetRootR();
    DgnLinkAddChildStatus        childStatus {root.AddChild(*leaf, index)};
    //  For a File or Folder link, childStatus is DgnLinkAddChildStatus::Success, but
    //  for a URL link childStatus is DgnLinkAddChildStatus::GeneralError
    TraceChildStatus (childStatus);
    if (DgnLinkAddChildStatus::Success == childStatus)
    {
        const StatusInt status {DgnPlatform::DgnLinkManager::WriteLinkTree(*linkTree, eeh)};
        return SUCCESS == status;
    }
    return false;
}

However, although I can build a DgnURLLink successfully, when I call my method it fails at root.AddChild(*leaf, 0). Here's the method that builds a DgnURLLink …

template<>
bool            CreateDgnLink<DgnURLLinkP>  (DgnLinkTreeBranchR root, TempDgnLinkTreeLeafOwner& leaf,  WCharCP url)
{
    bool      created    {false};
    int       status     {-1};
    leaf      = DgnPlatform::DgnLinkManager::CreateLink(status, DGNLINK_TYPEKEY_URLLink);
    if (SUCCESS == status)
    {
        DgnURLLinkP    urlLink = dynamic_cast<DgnURLLinkP>(leaf->GetLinkP());
        created = urlLink->SetAddress (url);
    }

    return created;
}

root.AddChild fails with DgnLinkAddChildStatus::GeneralError.  Is there something about a DgnURLLink that I've not considered?


Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>