What is unique in Document so that I can use IEqualityComparer on it

What is unique in Document so that I can use IEqualityComparer on it

sahin.ikbal
Advocate Advocate
548 Views
4 Replies
Message 1 of 5

What is unique in Document so that I can use IEqualityComparer on it

sahin.ikbal
Advocate
Advocate

I have some document elements from link documents or primary document.
I want to get if they are from any link document which RevitLinkInstances they are from.
From Element I can get its parentDocument, I can compare with all available documents and gather Their RevitLinkInstances per element.
But how do I know that both documents are same?

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

Sean_Page
Collaborator
Collaborator

I have found the best way to do this is to make sure that when you store the docs, you store them in a dictionary or sorted list that has a Key / Value relationship and then use project name or number or both to compare and pull from the dictionary. You could also just search for the element in the doc and if it returns a null then you know its not that doc.

 

Then when you pull the Document from the If they are workshared, you could use the WorksharingCentralGUID property and compare those.

 

However, I don't believe there is a straight forward and easy way to compare them like GUID or Id.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 3 of 5

RPTHOMAS108
Mentor
Mentor
Accepted solution
public override int GetHashCode()

 

Note the 'override' keyword i.e. it isn't just inherited from Object with dubious implementation.

 

RevitAPI.chm:

"The hash code is the same for document instances that represent the same document currently opened in the Revit session. The hash code is generated when a Revit file is opened or created in session. If the same Revit file is opened later (in the same session or a different session) the hash code will not be the same."

Message 4 of 5

Sean_Page
Collaborator
Collaborator

@RPTHOMAS108 

I know I have tried for a while to figure out how to really make this work for much of anything, and although if you only have work to do in a single session then this would work great, but unfortunately for me that most often isn't the case as we need persistent data.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 5 of 5

RPTHOMAS108
Mentor
Mentor

Yes that is true it is an in-memory thing but I was thinking @sahin.ikbal was only dealing with documents that were opened in the active session. i.e. for when a project is loaded the links open in the background becoming part of the document set.