Search code examples
autodesk-forgeautodesk-model-derivativeautodesk-bim360autodesk-designautomationautodesk-data-management

Autodesk Forge Data Management References API does not list Revit References


My goal is to compute a Revit model with the design automation API. The Revit model is hosted on BIM360 docs. The Revit model contains links/references to other models. Those references were created in Revit and all refer to models also hosted on BIM360 docs.

In order to submit the workitem to the design-automation API, I need to know all referenced files. This is described here.

However, when I query the references endpoint of the data management API {{FORGE_HOST}}/data/v1/projects/:project/versions/:version/relationships/refs, I get an empty data object.

I would have expected to get the versions of the referenced items.

One proposed workflow seems to be to upload files to BIM360 using the "upload linked files" function in the BIM360 docs frontend, see this blog post. Doing so, I do get the references using the above mentioned references endpoint. However, this does not work for our organisation and workflows, as more and more references are added during the planning phase. Moreover, some files reference each other, which also cannot be accomplished using the "upload linked files" function. The blog also mentions the forge API to link files, but we do not want to manually link models using the forge API, but would like to use the functionality provided by Revit.

How can I extract/query Revit references for Revit files that have been linked using referencing within Revit?


Solution

  • Updates

    The thing is changed now. To get Revit References with Forge Data Management API, the models need to be matched the following:

    Ref: https://knowledge.autodesk.com/support/revit-products/troubleshooting/caas/sfdcarticles/sfdcarticles/Collaboration-for-Revit-Local-links-not-visible-on-the-cloud.html

    If your Revit models are either of the above, the Revit API way is another choice. You may write a Revit Plugin that runs on Revit Desktop to read Revit links data before running the Design automation workitem you mentioned.

    ==========

    The Autodesk Desktop Connector would be the best choice to set up the references without using upload linked files or Forge DM API I shared in the blog.

    If you just want to dump link info, we can take advantage of Revit API to do so. Here is a code snippet for you. (Before running on Forge Design Automation API for Revit, TaskDialog.Show need to be removed)

    https://thebuildingcoder.typepad.com/blog/2019/06/accessing-bim360-cloud-links-thumbnail-and-dynamo.html

      // Obtain all external resource references 
      // (saying BIM360 Cloud references and local 
      // file references this time)
    
      ISet<ElementId> xrefs = ExternalResourceUtils
        .GetAllExternalResourceReferences( doc );
    
      string caption = "BIM360 Links";
    
      try
      {
        int n = 0;
        var msg = string.Empty;
    
        foreach( ElementId eid in xrefs )
        {
          var elem = doc.GetElement( eid );
          if( elem == null ) continue;
    
          // Get RVT document links only this time
    
          var link = elem as RevitLinkType;
          if( link == null ) continue;
    
          var map = link.GetExternalResourceReferences();
          var keys = map.Keys;
    
          foreach( var key in keys )
          {
            var reference = map[key];
    
            // Contains Forge BIM360 ProjectId 
            // (i.e., LinkedModelModelId) and 
            // ModelId (i.e., LinkedModelModelId) 
            // if it's from BIM360 Docs. 
            // They can be used in calls to
            // ModelPathUtils.ConvertCloudGUIDsToCloudPath.
    
            var dictinfo = reference.GetReferenceInformation();
    
            // Link Name shown on the Manage Links dialog
    
            var displayName = reference.GetResourceShortDisplayName();
            var path = reference.InSessionPath;
          }
    
          try
          {
            // Load model temporarily to get the model 
            // path of the cloud link
    
            var result = link.Load();
    
            // Link ModelPath for Revit internal use
    
            var mdPath = result.GetModelName();
    
            link.Unload( null );
    
            // Convert model path to user visible path, 
            // i.e., saved Path shown on the Manage Links 
            // dialog
    
            var path = ModelPathUtils
              .ConvertModelPathToUserVisiblePath( mdPath );
    
            // Reference Type shown on the Manage Links dialog
    
            var refType = link.AttachmentType;
    
            msg += string.Format( "{0} {1}\r\n", 
              link.AttachmentType, path );
    
            ++n;
          }
          catch( Exception ex ) // never catch all exceptions!
          {
            TaskDialog.Show( caption, ex.Message );
          }
        }
    
        caption = string.Format( "{0} BIM360 Link{1}", 
          n, Util.PluralSuffix( n ) );
    
        TaskDialog.Show( caption, msg );
      }
      catch( Exception ex )
      {
        TaskDialog.Show( caption, ex.Message );
      }