Search code examples
autodesk-forgeautodesk-viewerautodesk-model-derivative

Getting Revit Element Id from the Model Derivative API


We are creating a table of all objects in a given view using the model derivative API (https://aps.autodesk.com/en/docs/model-derivative/v2/reference/http/metadata/urn-metadata-guid-GET/), then getting the 'externalId' for each object. For 99% of objects, we can convert the last set of characters in the externalId from hexadecimal to decimal and match it with the Revit Id. We're having issues with a subset of objects that the externalId no longer converts to the correct Revit Id. Revit Id not Matching Element Id

I see in this question that the model derivative API won't return hidden properties (like ElementId), is there a way to get it with Design Automation? It's in the name in the viewer, and I can see it in the online console, but are there any API calls that can retrieve it?

And finally, why would the externalId now differ from the Revit Id, can this change due to copying / worksharing?

Edit:

After more research and this post I see that the externalid / RevitId difference is a feature of workshared models, and I don't see a way to get the Revit Id from the model derivative API. The two solutions I can see are:

  1. Adjust workflow to use external/uniqueId from the start
  2. Use the Viewer API to search by Revit Id and map to dbId that way

Are there any other APIs that can provide the Revit Id?


Solution

  • The externalId is a special type of ID provided by the Model Derivative service that is guaranteed to be "stable" or "persistent" (meaning that it will remain the same between different versions of the same design), however there is no guarantee as to how the ID will look like. For some design files it may look like a GUID, for other design files it could be a JSON array of numbers.

    Adjust workflow to use external/uniqueId from the start

    Yes, this is the recommended approach. If you're building an APS application that will link some kind of external data to individual design elements, it's a good idea to use the externalId as-is. That way your application could support other file formats as well.

    Use the Viewer API to search by Revit Id and map to dbId that way

    Yes, this would also work, as long as you'd be working with Revit designs only. You could either try and retrieve the element ID from the name of the corresponding node in the instance tree (using tree.getNodeName(dbid)), or from its properties (using viewer.getProperties(dbid, ...)):

    enter image description here

    enter image description here