Will Element Id Changed after file synchronization?

Will Element Id Changed after file synchronization?

NGM_AiYo
Advocate Advocate
1,339 Views
4 Replies
Message 1 of 5

Will Element Id Changed after file synchronization?

NGM_AiYo
Advocate
Advocate

I've made a plugin to crate hole on .rvt file. 

It has an updater to detect pipe move and reset hole location.

When two people working together on the same project,  the location of the hole became a mass. And schema data on pipe,  I use dictionary to save hole Id and wall Id, program can not get the current hole Id in data.

So my guess is maybe the Id has changed.

Can someone tell me the reason.  And better be a solution to this problem. Thanks.

0 Likes
Accepted solutions (1)
1,340 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni
Accepted solution

Yes.

 

The element id is assigned individually for each user and can change to ensure it is unique within the Revit model when two separately edited models are synchronised. 

 

The UniqueId property returns an element identifier that does not change during this process. For the difference between the two, please read the UniqueId documentation:

 

https://www.revitapidocs.com/2022/f9a9cb77-6913-6d41-ecf5-4398a24e8ff8.htm

 

> The UniqueId can be used to store an identifier in an external database and to retrieve the same element in the future if it still exists. This id can be passed to the Document's Element property to retrieve the element. The UniqueId is stable across upgrades and workset operations such as Save To Central, while the ElementId property may change.

 

Please refer to The Building Coder topic group on element ids and UniqueIds for more information:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 5

NGM_AiYo
Advocate
Advocate

thank you for your suggestion.  I use Element.UniqueId instand of ElementId.

0 Likes
Message 4 of 5

NGM_AiYo
Advocate
Advocate

I noticed a strange phenomenon.

I use schema to save data,  schema1  data type is Dictionary<ElementId,  string> ,  and elementId  is from element in editing document. Next schema2 data type is Dictionary<string,  ElementId> ,  this time elementId is form element in link document.  Before I sync file, all is fine. After file synchronization,  the data of schema2 changed,  all elementId became -1.  And at same time,  there is no influence on schema1's data.  At last I change data type to int. My revit version is 2019.  

Message 5 of 5

jeremy_tammik
Alumni
Alumni

That is not strange at all.

 

It is intentional and documented:

 

https://thebuildingcoder.typepad.com/blog/2011/06/extensible-storage-features.html#7

 

For further information, please study all the explanations on extensible storage:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23

  

Oops... on second thoughts, the behaviour you describe is different from what I thought and expected. Have you checked the documentation whether it is officially explained? In any case, it just goes to show that you should not use element ids in an unsynchronised local file at all. The element id handling in extensible storage may assume that you are not synchronising at all, or have already synchronised before storing the data.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes