Revit API Forum
Welcome to Autodeskā€™s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

Can I Filter different BuiltInCategories at same time

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
hctungBHP7B
271 Views, 6 Replies

Can I Filter different BuiltInCategories at same time

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.

6 REPLIES 6
Message 2 of 7
jeremy_tammik
in reply to: hctungBHP7B

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

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 3 of 7
Yien_Chao
in reply to: hctungBHP7B

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()
Message 4 of 7
hctungBHP7B
in reply to: Yien_Chao

@Yien_Chao Thank you ! That is exactly what I need! 

 

Message 5 of 7
hctungBHP7B
in reply to: jeremy_tammik

@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.

Message 6 of 7
jeremy_tammik
in reply to: hctungBHP7B

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.

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 7 of 7
jeremy_tammik
in reply to: hctungBHP7B

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

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community