Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unique Id vs ElementId, which identifier to stored in the external database.

4 REPLIES 4
Reply
Message 1 of 5
bsyap
10595 Views, 4 Replies

Unique Id vs ElementId, which identifier to stored in the external database.

Hi Everyone,

 

I am trying to develop a Revit extension which help to export/import Revit building model to structural analysis software. In the external database, i am not sure which identifier to be stored in order to retrieve the same element after successive import/export call between Revit and analysis software.

I wish to implement something described as below:

 

1)After structural analysis software made changes to the building model, it export these changes to a external database. My extension will load the external database, retrieve the 'changed' element based on the identifier(i.e document.get_element(ElementId/UniqueId)) in Revit and apply the changes to the retrieved element. However these ids are used internally in Revit and i don't know how Revit generate the ids which make me hard to identify which element is changed outside Revit. 

 

2)Revit user can aslo made change to the building model and send this changes back to structural analysis software. However, in the structural analysis software, there is no unique identifier for each element like Revit do. Hence, i think i need to create one.(i.e use GUID). But this identifier is not the same as the one used in Revit. How do i generate a same identifier which is used to identify the element in both Revit and structural analysis software?

 

I get some suggestion as below:

 

1)On export from Revit, create a set of GUIDs for the exported elements. Besides that, each exported element's ElementId must be saved as well. 

How do i generate a Guid which is used to identify exported element? 

 

2)On import to Revit, check for an existing object with the standard GUID or else create a new one.

 

So, Structural analysis software need to generate the Guid in the same way described in(1) so that the guid is identical to both Revit and Analysis software? Please correct me if i am wrong or something i have missed out.   

 

Does anyone have other suggestion? Any help is appreciated. 

 

 

4 REPLIES 4
Message 2 of 5
GonçaloFeio1321
in reply to: bsyap

The Document class has some GetElement methods to access Elements by their index (ElementId or Guid).

The Guid is for that case a string, so you need to get the elements like this:

 

Guid uniqueId = something;

Element fetch = doc.GetElement(uniqueId.ToString());

 

The opposite is:

 

Guid elementGuid= new Guid(element.UniqueId); 

 

In this case, the UniqueId is also a string, so you need to convert it to a Guid struct.

Message 3 of 5

The above answer/suggestion is not entirely correct. Revit’s UniqueID is not a Guid. It is a string. Part of the string is a Guid, but the whole thing is not – it needs to be treated as a string identifier.
 
To get a unique Id for an element use: Element.UniqueId
To retrieve an element by its unique Id: document.GetElement( uniqueId )
 
By the way, the difference between UniqueId and regular element Id is its stability (or instability, respectively) in a work-sharing environment. While regular element Ids are unique only in documents that are not work-shared, Unique Ids are stable and still unique even in document that are shared (and modified by) several local copies and then synchronizes with the server version.
 
Neither of the identifiers types are stable across individual Revit documents – it means that elements in different, independent Revit models may have the same Ids (as well as UniqueIds) assigned.
 
Arnošt Löbel
Sr. Principal Engineer
Autodesk, Revit R&D 
Arnošt Löbel
Message 4 of 5
bsyap
in reply to: arnostlobel

Hi,

 

I understood the relationship between UniqueId and regular element id. But now, i do not know how to keep track of structural element in a building model in both Revit and structural analysis software after successive import/export call between Revit and analysis software.

I wish to implement something described as below:

 

1)After structural analysis software made changes to the building model, it export these changes to a external database. My add-in will load the external database, retrieve the 'changed' element based on the identifier(i.e document.get_element(ElementId/UniqueId)) in Revit and apply the changes to the retrieved element. However these ids are used internally in Revit and i don't know how Revit generate the ids which make me hard to identify which element is changed outside Revit. 

 

2)Revit user can aslo made change to the building model and send this changes back to structural analysis software. However, in the structural analysis software, there is no unique identifier for each element like Revit do. Hence, i think i need to create one.(i.e use GUID). But this identifier is not the same as the one used in Revit. How do i generate a same identifier which is used to identify the element in both Revit and structural analysis software?

 

I get some suggestion from Jeremy's blog:

 

1)On export from Revit, create a set of GUIDs for the exported elements. Besides that, each exported element's ElementId must be saved as well. 

How do i generate a Guid which is used to identify exported element? 

 

2)On import to Revit, check for an existing object with the standard GUID or else create a new one.

 

So, Structural analysis software need to generate the Guid in the same way described in(1) so that the guid is identical to both Revit and Analysis software? Please correct me if i am wrong or something i have missed out.   

 

Does anyone have other suggestion? Any help is appreciated. 

Message 5 of 5
jeremytammik
in reply to: bsyap

Dear Bsyap,

 

If the elements originate in Revit and come equipped with a unique id, I would use that to identify them in both environments.

 

If the elements originate outside of Revit and you need to assign a perpetual unique identifier to them before they automatically become equipped with a Revit unique id, I would use a standard GUID in addition, just like you described.

 

This makes things much more complicated than just using the Revit unique id, though.

 

To generate a GUID, you can simply use the standard Windows or .NET API.

 

http://lmgtfy.com/?q=.net+guid+generate

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community