Jan 25, 2024
How To Get Material Layers from Wall, Floors and Roofs
Learn how to get material layers from WallType, FloorType, RoofType, CeilingType by accessing CompoundStructure.
How to Get Material Layers?
Since you are here, probably you are wondering:
"How do you get Material Layers of our WallType, FloorType, RoofType and CeilingType?".
Well, I'm glad you asked!
I will explain everything on an example of WallTypes, and the similar logic will apply to other elements.
First of all, let's think of Revit UI functionality to access this information.
Overall it's not complicated, but let's explore a few details.
💡Here is the pyRevit Template I will begin with.
First of all we need some Wall elements. You probably already have a code snippet where you get them, but I will leave a snippet for others to use:
Here is a simple Snippet to get user selection.
1️⃣ First of all we try to get current user's selection
2️⃣ Then if nothing is selecte, we will prompt PickObjects selection
3️⃣ Since we only want to work with Walls, let's make a simple filter.
4️⃣ Lastly, let's give a warning if user hasn't selected any walls.
Now once we have Walls, we can start looking inside of them. I would recommend you to use Revit Lookup and look inside until you find Layers. Then it becomes very easy to follow the same logic in your code.
Now we have all layers, we can read their properties.
In my case, I want to read Material Names and Thicknesses of each layer and print in the console.
It might be used later for renaming our types 😉.
Here is the code snippet:
Keep in mind that some layers have no material assigned to them, so they will return
ElementId(-1). So don't forget to make an if statement before you try to get Material by using doc.GetElement(e_id)
💡Also will notice that I multiplied my width with
30.48 for rounding.
You can use a better approach for rounding using UnitUtils Class.
Here is the Final Code. And you will find the screenshot example on the bottom ;)
⌨️ Happy Coding!
🔥 Amazing Revit API Resources!
Join Revit API
which is already read by 2200+ people!
Get short Revit API Lessons and Tips directly in your mail!