Document Session ID

tobias.floescher
Contributor

Document Session ID

tobias.floescher
Contributor
Contributor

Hello

 

Sorry for my stupid question, can't find an answer. But I'm sure there is a way.

 

Is there something like a session id for open documents?

I would like to uniquely identify a Autodesk.Revit.DB.Document object, for example in the ViewActivated Event. This is needed while more than one document can be open at the same time in Revit. Because I hold some stuff in memory, I need to know to which document it belongs.

 

The DocumentPath as Id is not an option, because newly created documents have a zero string (could be occur more than one as well in a session)

 

Many thanks for hints

Tobias

0 Likes
Reply
Accepted solutions (1)
1,107 Views
4 Replies
Replies (4)

jeremytammik
Autodesk
Autodesk

Dear Tobias, 

 

As we all know, there are no stupid questions.

 

Sometimes people would be better served searching for an answer themselves before asking others. It seems to me you have already searched, with no fruitful results. Thank you for that. However, there is some information on this already out there, waiting to be found:

 

Every Revit project includes a singleton ProjectInformation database element. Every database element has a unique identifier. So, theoretically, you could use that to uniquely identify a project.

 

Unfortunately, if I create a project A, and then copy it for reuse in project B, the two ProjectInformation elements will have the same unique id, so this solution only works if you can guarantee that no such copy will ever be created:

 

https://thebuildingcoder.typepad.com/blog/2017/12/project-identifier-and-fuzzy-comparison.html#2

 

Here is a some further analysis of this situation:

 

https://the3dwebcoder.typepad.com/blog/2015/07/implementing-mongo-database-relationships.html#2

 

To address this, I suggested a different and safer solution using an extensible storage schema and a named GUID storage for project identification instead:

 

https://thebuildingcoder.typepad.com/blog/2016/04/named-guid-storage-for-project-identification.html

 

I hope these various thoughts and suggestions can help.

 

Please do let us know how you end up solving this.

 

Thank you!

 

Cheers,

 

Jeremy

  



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

0 Likes

tobias.floescher
Contributor
Contributor

Hello Jeremy

 

Indeed, I searched before without a satisfying result.

I came to the same conclusion as your solutions. I was hoping there was something else 😉

 

Possibly use the combination of unique identifier and the file path, but this is not very elegant. I think I will end up in use the solution with extensible storage. maybe a second scheme, not the same as my plugin use for storing its data.

 

Thank's a lot for your answer

 

regards,

tobias

0 Likes

RPTHOMAS108
Mentor
Mentor
Accepted solution

Some documents don't contain a path (yet to be saved ones).

 

Document.GetHashCode has served me well over the years. Mainly I use this in static variable to see if the current document has switched via the ViewActivatedEvent.

0 Likes

tobias.floescher
Contributor
Contributor

Ah very nice. thank you for that.

 

read the manual:

https://www.revitapidocs.com/2020/006a71c2-4393-e036-9987-14467342a7d3.htm

0 Likes