Python: Get all materials in elements from category

Hi.
Recently I was looking for a way to get all materials used in model (like in Material Takeoff), but in Python script. This seems impossible to do in easy way, therefore I decided to do it manually with only specific categories:

  • compound types: Wall, Floor, Roof, Ceiling
  • noncompound: Generic Model, Curtain Panels, Columns, Casework, Stairs, Structural Framing/Foundation.

I created script for compound elements, but have no idea how to properly start with the others. I know I have to dive deep into inside Geometry.
Do you have any clues or code examples how to do it properly and/or efficiently?

Thanks in advance for help.

Hi @Imigas,

As a start you need to collect all the instances of all types in all the categories you want to search. So you could write a collector function to do so with filters:
https://www.revitapidocs.com/2020/263cf06b-98be-6f91-c4da-fb47d01688f3.htm

If you have those Elements, you can use Element.GetMaterialsIds to collect the materials available in each familyinstance.
https://www.revitapidocs.com/2020/6011352e-151b-b8ac-14cc-45970f2fe5ad.htm

You can use the Ids together with Element.GetMaterialVolume to get the actual volume per Material, per element.
https://www.revitapidocs.com/2020/99b50d87-bfa6-ca67-e205-47b22cad6587.htm

I dont know if this is the best approach, It is not faster then the Material Take off I think.

Keep us posted on your progress

Element.GetMaterialsIds sounds awesome and I think it will do the job.
I know this whole idea may look like an overkill, but we need to export Excel schedules with specific style and data filtering. Time is not a problem. The script may run 5-10min and still it will be faster than manual Material Takeoff exporting, formating and checking, especially after multiple actualizations.

Thanks for reply and information.

I can confirm that Element.GetMaterialsIds is enough as long as you accept mapping this function on all necessary categories.
I will mark Joelmick answer as solution unless someone has better/more efficient idea.
Thanks again.