0

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?

kai
  • 59
  • 6
  • 1
    I think you need to use the Autodesk Desktop Connector application to upload the files to ensure that these references are correctly set. – Albert Szilvasy Jul 29 '21 at 14:55
  • Thank you @AlbertSzilvasy for the hint to the Autodesk Desktop Connector. Does the Autodesk Desktop Connector support linking BIM360 Revit Models with each other (all models are hosted on BIM360, as opposed to some locally, some in the cloud) – kai Jul 30 '21 at 11:27

1 Answers1

1

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 );
  }
Eason Kang
  • 6,155
  • 1
  • 7
  • 24
  • Thank you for the quick response. So do I understand it correctly that we need to set the references in Revit AND use the desktop connector to set references? I am not sure if this actually works for us, but we will give it a try. – kai Jul 30 '21 at 11:13
  • Also thank you for the code snippet which would dump link info using the Design Automation API. However, this does not work for us, as we need the info prior to using the Design Automation API (we want to provide the link info with the workitem request). Isn't there an API (BIM360 / Data Management / Model Derivative) that delivers Revit reference information? – kai Jul 30 '21 at 11:15
  • I updated my answer above. If your models are configured with those 3 listed methods, then you can get the references info with Data Management (Docs). – Eason Kang Aug 02 '21 at 03:46
  • Thank you Eason! Your links helped us and we can now get the references from the versions/:version/relationships/refs API (using C4R Models and the publish/link workflow explained in the reference) – kai Aug 03 '21 at 05:54