LearnRevitAPI
🔍Get Existing Types Before Duplicating Them
Jan 17, 2025
Get/Create Wall Type
I was helping one of the students inside the course to finish a cool tool - Split Wall into Material Layers. (Might share the full code later)
And for one of the steps - we needed to get existing WallType with a name, or create a new one if it doesn't exist. Simple step, but might be a bit tricky for beginners.
So, let me share how I do that and I think many of you will find it useful for your own code.
Get Existing Type by Name
Firstly, let's try to get WalLType with a name in case it already exists. Very important step to avoid duplicates and errors.
There are many ways to do that, but one of the most efficient one would be to use ElementParameterFilter.
Filters might look complicated in Revit API, but it's very similar how we use them inside of Revit. And you need to use them a few times with code to get a hang of it.
In this case we will create a filter to check if TypeName parameter has exactly the value that we need. So we need to specify:
Parameter
Evaluator
Value
And apply it on FilteredElementCollector.
Same logic in Revit:
How do we do that with with Code? We follow the same steps as manually.
Here is the code:
If you are confused, you can use this YouTube tutorial to help you understand this filter.
What if it doesn't exist?
Well, then we go to plan B - Release the Dragon 🐉
Oh wait, that's the wrong plan B...
Here is how to create a new WallType in case it doesn't exist:
I know it looks like a lot, but these are the same steps that you would do manually, aren't they?
Select WallType
Duplicate
Adjust Type name
Adjust Structure Layers:
Functions
Material
Width
That's exactly what's happening inside this code.
Same steps as manually but with code.
💡Also, don't forget to use Transaction since we make changes to our projects.
And here is the result:
EF Super-Duper Concrete Wall 3000
Would you name it differently?
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 7500+ people!
The Bundle Price Increases in
Join Today with 30% OFF.