LearnRevitAPI
![](https://framerusercontent.com/images/zMFB840Y52OLteloUT4BRuogE.png)
![](https://framerusercontent.com/images/U9zjOvD4k3m6cIJd5bOiu960DeI.png)
Nov 7, 2023
Filter Elements with Parameters
![](https://framerusercontent.com/images/Sd5FTaxiqzG7oeH1ykV6yypUzXo.png?scale-down-to=512)
If you are a Revit API enthusiast, then at certain point you wanted to get your elements based on a parameter value.
We can get elements with OfClass or OfCategory and then make a for loop...
But what if you want to make it more efficient?
💡Let's learn how to use ElementParameterFilter
😉Learn in Action
By the end of this email you will understand how ElementParameterFilter works and you will have a function to get elements by Type/Family Name.
👀 Isn't it what you always wanted ?
🧩 ElementParameterFilter
ElementParameterFilter allows us to create a filter that targets specific parameter. We can provide a value and choose evaluator.
💡 And it's not that complicated once you make it work once!
There are 4 constructors and they are very similar. They all need FilterRule
![](https://framerusercontent.com/images/iPuYl0Z8LpMSodIx8AHDCgPuzg.png)
💡 Let's use the first one as it's the most common and simple one.
🤔What is FilterRule?
FilterRule class allows us to provide Parameter, Evaluator and Value to check. And there are different classes depending on the StorageType of the parameter.
![](https://framerusercontent.com/images/7J5cB5xPlNzfrZj49NG4nPFnRZo.png)
![](https://framerusercontent.com/images/R9c5ftDEBwzNkh9djxzTe5QuR8.png)
![](https://framerusercontent.com/images/pdtaw6IAgVtODZXZXZFvvPIVNU.png)
![](https://framerusercontent.com/images/tnIbFQhlwMLF0N0Crbj6KxQuQR0.png)
In our case, we will be checking Type/Family Names, so we need to choose FilterStringRule for that.
✨How to create FilterRule
If you compared constructors above, you might have noticed that all of them require similar arguments.
valueProvider | evaluator | ruleValue
Before I explain how to create them, let's look at Filters in Revit UI.
When you create View Filters we need to define Filter Rules, and it's very similar to Revit API.
![](https://framerusercontent.com/images/6vWnwDqnCbuTWhP7A8KXwuBlWI0.png)
We need to:
1️⃣ Define Parameter
2️⃣ Choose Evaluator
3️⃣ Provide Value
Let's do the same with Revit API.
1️⃣ Define Parameter
To provide a parameter for a rule we need to use ParameterValueProvider.
It has very simple constructor that takes ElementId of a Parameter. And we can get it by using BuiltInParameter Enumeration.
![](https://framerusercontent.com/images/CoxEK9w0msTXL0zJPjkzY0X4aHE.png)
2️⃣ Evaluator
Next argument is - Evaluator.
There are many classes to choose from, but it's actually quite simple.
![](https://framerusercontent.com/images/PjoaoZ1BLzQ166QRtgEkQdX0ThI.png)
First of all you need to decide is your parameter Text or Numbers based?
Secondly, you need to choose evaluator type.
Do you want Equals, Less, Greater, Contains...
![](https://framerusercontent.com/images/lpkZd9yfDcLANLxYurbF96ngKP8.png)
💡 I will choose FilterStringEquals because I want the exact match!
3️⃣ Value
Lastly, we need a value.
This should match StorageType of your parameter. Since we are dealing with Type and Family names, we want to provide a string.
![](https://framerusercontent.com/images/EiZagTF4HY9Kc25g2CaWoLTMWXY.png)
✅Create Filter
We have all the arguments so we can put them to use.
1️⃣ Let's create FilterStringRule
2️⃣ then we can use it to create ElementParameterFilter
3️⃣ and lastly we can use it with WherePasses() in FEC
![](https://framerusercontent.com/images/iJLNNuc32UD3AU8vdAB34M9Y4c.png)
💡 Also note that Revit API had some changes in 2022, so FilterStringRule has removed caseSensetive parameter after 2022.
👉Reusable Function
Lastly, let's make it a function so you can reuse it in your own script by just providing correct Type Name.
And if you want to change it to Family Name then change BuiltInParameter to ALL_MODEL_FAMILY_NAME
![](https://framerusercontent.com/images/3UlqHNZN7O0NO3yCNaX2zUAxdio.png)
Now you can modify very little to make it work for other uses.
1️⃣ Change BuiltInParameter
2️⃣ Choose Evaluator
3️⃣ Choose FilterRule Class
4️⃣ Change Value
5️⃣ Bonus: extend FIlteredElementCollector methods.
💪 Practice it for your own use-cases.
Once you adjust it to your own needs it will click and you won't have issues using it anymore! Now you know how to use ElementParameterFilter
🔥FREE PDF Guide
P.S.
Make sure that you have my FREE PDF guide on FilteredElementCollectors. Half of this guide is about Revit API filters, so you will learn even more!
There are plenty of examples you can use!
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 6700+ people!
![](https://framerusercontent.com/images/svHzzMLtnnRCxtCUwbgAm6CUeB8.jpg)
![](https://framerusercontent.com/images/Y44kwhY0i7q37LzXUjrlxeGUo.jpg)
![](https://framerusercontent.com/images/lqKYmh8rqwZwgY2C9MSQER6iBCI.jpg)
![](https://framerusercontent.com/images/SyGCvJ3dbHsJEyklWWBhweY.jpg)
![](https://framerusercontent.com/images/DwiaUdmQHs3FVdDH2PXwAr0Y.jpg)