Why I can't use WhereElementIsElementType and WhereElementIsNotElementType in the same class

Why I can't use WhereElementIsElementType and WhereElementIsNotElementType in the same class

duongphong29
Enthusiast Enthusiast
1,552 Views
2 Replies
Message 1 of 3

Why I can't use WhereElementIsElementType and WhereElementIsNotElementType in the same class

duongphong29
Enthusiast
Enthusiast

Hi!

 

I am trying to get FamilySymbols and FamilyInstances of the same category. Here is my code:

            ElementId targetCategoryId = elementList.ElementAt(0).Category.Id;
            FilteredElementCollector collection = new FilteredElementCollector(doc);
            ElementCategoryFilter filterCategory = new ElementCategoryFilter(targetCategoryId);
            IList<Element> allFamilyInstances = collection.WherePasses(filterCategory).WhereElementIsNotElementType().ToElements();
            IList<Element> targetFamilySymbols = collection.WherePasses(filterCategory).WhereElementIsElementType().ToElements();

 

The problem is the list allFamilyInstaces give me exactly what I want but targetFamilySymbols list gives me zero item.

When I move the line of code 

            IList<Element> targetFamilySymbols = collection.WherePasses(filterCategory).WhereElementIsElementType().ToElements();

to before the allFamilyInstances list. The result is vice versa, targetFamilySymbols gives all family symbols but allFamilyInstaces gives me none.

 

Can someone explain for me why? And how can I deal with this? Thank you

0 Likes
Accepted solutions (1)
1,553 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

Every subsequent filter that you apply is added to all the previous filters as a logical AND.

  

So, if you apply two mutually exclusive filters, one after the other, the result will always be void.

  

https://thebuildingcoder.typepad.com/blog/2021/02/splits-persona-collector-region-tag-modification.h...

  

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

duongphong29
Enthusiast
Enthusiast

Oh, I understand, thank you 

0 Likes