Changing document ids

I’m keeping a dictionary with open documents and associated settings. I use the DocumentIDs as the dictionary keys.
Unfortunately I’ve noticed that if a document is copied manually or saved using “Save as…” the new file will (of course) keep it’s document id.
This leads to trouble as I end up with the same key for multiple documents if I open both, the original and the copied file.

Unfortunately, the DocumentID property is private. I could probably change it via my new reflection skills. Is there any reason why I should not do this?

You are probably the first one trying. Sounds like a workaround for a workaround for a workaround…

Anyway, you could also check for other things like date of creation, etc making a checksum of all this and use this as a unique identification.

I’ve just realized that I can use the document itself as a dictionary key – which goes into the same direction as you propose.
Probably best to not fiddle around too much with Davids stuff :slight_smile:

1 Like

While documents are loaded they remain the same class instances. You could use ReferenceEquals() to check whether any given two GH_Documents are the same instance.