Hi, I am wondering that is it possible to filter different BuiltInCategories at same time?
Because I want to improve my code efficiency in my big Revit file, so I only want to filter once
Or Any other ways can get instances of those BuildInCategories in a list??
bic_beam = DB.BuiltInCategory.OST_StructuralFraming
bic_collumn = DB.BuiltInCategory.OST_StructuralColumns
bic_beam_tag = DB.BuiltInCategory.OST_StructuralFramingTags
bic_collumn_tag = DB.BuiltInCategory.OST_StructuralColumnTags
So far, I only know basic collector and filter to achieve one BuiltInCategory.
collector = DB.FilteredElementCollector(doc, doc.Active.Id)
beam_filter = DB.ElementCategoryFilter(DB.BuiltInCategory.OST_StructuralFraming)
beam_elements = collector.WherePasses(beam_filter ).ToElementIds()
Thanks for your time, Any helpful advise is very appreciated.
Solved! Go to Solution.
Solved by Yien_Chao. Go to Solution.
First, a comment on your second code snippet: it is always advisable to use the filter shortcuts. In this case, use OfCategory instead of ElementCategoryFilter + WherePasses. It is shorter, clearer, and guarantees that you are using a quick collector.
Second, the answer to your question is yes. I think this is the one and only purpose of the FilterCategoryRule class:
https://www.revitapidocs.com/2022/7df5b10b-c423-b5c8-6492-1274d7a447d9.htm
Read the article on how to use FilterCategoryRule for more info:
https://thebuildingcoder.typepad.com/blog/2018/05/how-to-use-filtercategoryrule.html
It also mentions how you can easily achieve the same without using FilterCategoryRule:
For yet more info, please refer to The Building Coder topic group on filtering for elements:
https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.9
you can also use multicategoryfilter : https://www.revitapidocs.com/2022/e43a304a-6931-7492-441c-3cac428f2431.htm
so instead of using categories Id, you will need a list of builtinCategory names
ex:
cat_list = [BuiltInCategory.OST_Walls, BuiltInCategory.OST_Windows, BuiltInCategory.OST_Doors,BuiltInCategory.OST_Floors,BuiltInCategory.OST_Ceilings]
types= List[BuiltInCategory](cat_list)
multiCat = ElementMulticategoryFilter(types)
Elements = FilteredElementCollector(doc).WherePasses(multiCat).WhereElementIsNotElementType().ToElements()
@jeremy_tammik Thanks for your detailed replies, I am really appreciated!
For my understanding, OfCategory and ElementCategoryFilter + WherePasses, That two method can achieve same goal. In addition, Those two ways are both quick filter. However, using OfCategory directly can be more readable and clearer.
Am I right? Please correct me if I am wrong. Thanks
FilterCategoryRule, Thank you this suggestion ,I will check which one is better comparing to ElemenetMulticategoryFilter.
> Please correct me if I am wrong.
No, that is absolutely correct.
> which one is better...
I prefer ElementMulticategoryFilter myself, now I think about it. It is clearer and more direct.
Thank you for raising this once again. I summarised our conversation on the blog:
https://thebuildingcoder.typepad.com/blog/2022/06/outer-walls-lookup-update-and-filtering.html#3