Search code examples
autodesk-forgerevit-apiautodesk-bim360

Error while linking Cloud Revit file using ExternalResourceReference - The ExternalResourceReference is not in a format that's supported by its server


I would like to link a cloud model into another Revit Model for Revit 2021 and below. After lots of exploration, one of my colleague was able to use ExternalResourceReference to successfully link the model for one of the project in Revit 2020(below is the code). But when I try to use the same code in a Revit 2021 project I'm receiving the following error:

The ExternalResourceReference (resourceReference) is not in a format that is supported by its server

var linkCloudPath = doc.GetCloudModelPath(); // the cloudpath of a BIM360 model
Guid linkedmodelguid = linkCloudPath.GetModelGUID();
Guid linkedprojectguid = linkCloudPath.GetProjectGUID();

Dictionary<string, string> Dictionary_ExternalResource = new Dictionary<string, string>(){
    {"LinkedModelModelId", modelGuid.ToString()},
    {"LinkedModelProjectId", projGuid.ToString()}
};

Dictionary<string, Guid> servers = new Dictionary<string, Guid>();

foreach (var service in ExternalServiceRegistry.GetServices())
{
    if (service.Name == "External Resource Service")
    {
        IList<Guid> server_ids = service.GetRegisteredServerIds();


        foreach (var server_id in server_ids)
        {
            servers.Add(service.GetServer(server_id).GetName(), server_id);
        }
    }
}

Guid BIM360ServerID = servers["BIM 360"];
ExternalResourceReference ERS = new ExternalResourceReference(BIM360ServerID, Dictionary_ExternalResource, "", "");
RevitLinkOptions options = new RevitLinkOptions(false);
LinkLoadResult result = RevitLinkType.Create(gcdoc, ERS, options); // error in this line
RevitLinkInstance.Create(gcdoc, result.ElementId);

There is no change in the code anywhere between 2020 & 2021.


Solution

  • Turns out that I just needed to add region the dictionary Dictionary_ExternalResource

    Dictionary<string, string> Dictionary_ExternalResource = new Dictionary<string, string>(){
        {"LinkedModelRegion","US" }, // added this line
        {"LinkedModelModelId", modelGuid},
        {"LinkedModelProjectId", projGuid}
    };