βΌοΈBLACK FRIDAY DEAL 20% OFF. Ends in:
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.
π‘Brainstorming
You can use Revit Lookup to inspect your elements until you find layers. You can follow this path:Wall -> WallType -> GetCompoundStructure -> GetLayers -> MaterialId
Overall it's not complicated, but let's explore a few details.
π‘Here is the pyRevit Template I will begin with.
1οΈβ£Select Elements
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.
2οΈβ£Get Layers
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.
As I've mentioned earlier, we need to look in WallType to get material layers.
There will be .GetCompoundStructure
method that returns CompoundStructure.
Then we can use GetLayers to get all material layers. Keep in mind it returns List<CompoundStructureLayer>
. So you can look in the Revit API Documentation what else we can get from them.
3οΈβ£Read Material
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.
β¨Final Code
Here is the Final Code. And you will find the screenshot example on the bottom ;)
β¨οΈ Happy Coding!
Join Newsletter
π© You will be added to Revit API Newsletter
Join Us!
which is already read by 7400+ people!
Ready to become Revit Hero for your office? Learn Revit API!
Join this comprehensive course that will guide you step by step on how to create your dream tools for Revit that save time.