Intersection of two ModelItemCollection objects

Intersection of two ModelItemCollection objects

rade_tomovic
Advocate Advocate
838 Views
6 Replies
Message 1 of 7

Intersection of two ModelItemCollection objects

rade_tomovic
Advocate
Advocate

Hello,

 

is there any built-in method which can return only model items contained in both ModelItemCollection-s (something like the intersection of two sets)? If not, what is the best way to achieve this? I was thinking about HashSet<ModelItemCollection> in order to use built-in HashSet logical operations, but I'm not quite sure how Navisworks Equals method works (or ValueEquals or whatever similar I've found in the API) so any help would be appreciated.

 

Thanks in advance

0 Likes
839 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

I'd try the built in Intersect of ModelItemCollection to start with, and if it doesn't work definitly hashset but using the modelitem InstanceHashCode.

Might be able to use the InstanceHashCode in lambda with the built in intersect too.

0 Likes
Message 3 of 7

rade_tomovic
Advocate
Advocate

There is no built-in method for the intersection, which will return a collection of intersected items, as far as I know.

0 Likes
Message 4 of 7

Anonymous
Not applicable

I have an extension method from Linq showing up. Don't know how it would do performance wise.

0 Likes
Message 5 of 7

rade_tomovic
Advocate
Advocate

Yes, this is a standard LINQ method which assumes that used collections have implemented IEqualityComparer. Maybe I can redefine my questions - I have a ModelItemCollection as an input and I'm using Navisworks Search API upon that collection. I need a collection which contains model items which weren't found by the current search.

0 Likes
Message 6 of 7

Anonymous
Not applicable

throwing a couple ideas to explore:

1. I have used modelitem as key of dictionary in the past fairly efficiently so I assume they do implement some comparison method (not sure what dictionary use)...

2. have you tried running the opposite search on the same set (negating the right conditions)?

3. there is an invert method on collection so if you create a collection of the result and inverse that, it should give you the rest

0 Likes
Message 7 of 7

rade_tomovic
Advocate
Advocate

Thanks for the ideas, I will try the first and/or the second. Model item (as well as almost every object in programming) implements Equals method, which should return true if both model items pointing to the same reference (memory location). Regarding the 3rd one, Invert method works only in a way to return invert selection using Navisworks document as an input, not the specific part (what I need here).

0 Likes