LearnRevitAPI

Jun 18, 2024

Create View Filters

If you needed to create View Filters, then you definitely thought about automating it. Luckily, it's not that complicated, and I will break it down for you in this lesson.

💡Let's Learn: How To use Create View Fitlers with Revit API

Create View Filters

In general, to create a View Filter, we need to:

🔸Select Categories
🔸Create Parameter Rules (Set: Parameter, Evaluator, RuleValue)
🔸Create ElementParameterFilter from rules
🔸Create ParameterFilterElement (View Filter)

Also, I will show you how to:

🔸Add View Filter to a view
🔸Apply some Graphic Overrides

Let's break it down.

1️⃣ Select Categories

Same as when we create a view filter in Revit's UI, we usually start by selecting the right categories.

You just need to create a List of ElementIds of your categories. Here is how to do that, and you can keep adding as many categories as you might need.

2️⃣Create Parameter Rule

Next we need to create a Rule. 

Same as in the Revit UI we need to select :

- Parameter
- Evaluator 
- Value

There are two ways to create rules, and they give you the same results. It's up to you to decide which one you prefer.

I will create the same filter for Wall's Function parameter to be equal to 'Exterior'

🅰️ As you can see we can either use direct classes like:

FilterIntegerRule, FilterStringRule, FilterDoubleRule and others...

Then, you would need to select the right class based on the parameter storage type. And provide ParameterValueProvider, Evaluator, and provide the value.

🅱️ Or We can use ParameterFilterRuleFactory.

The trick here, is that you will have to provide the right arguments and their amount, depending on the StorageType of the parameter.

Multiple Rules

Also, if you want to provide multiple parameter rules, you can combine them in a list like that.

👀 You will also notice an additional FilterStringRule as rule_2.


3️⃣ Create View Filter

Once you've defined:

- Filter Name
- Categories
- Rules

You are ready to create an actual View Filter by using the ParameterFilterElement.Create method.

Here is the code.


4️⃣ Apply to a View

Lastly, let's add this filter to a view and assign some simple Graphic Overrides. I will create simple graphic overrides to make a thick blue like for CutLines.

To add a filter, we would need to use AddFilter or SetFilterOverrides method. Both of them will add filter to a view if it's not added yet.


⌨️ Complete Code

Here is the complete code snippet to avoid confusion.

✨Bonus Tool

You might be wondering how to create view filters based on a parameter value. So, I want to show you a more practical example. 

We'll get all WallTypes in the project and create view filters for each one based on their names.

Here is the code Snippet:

🚧 Adjust to your own needs to create even more View Filters.

And also check out this video if you want to learn more about View

Enjoyed Newsletter?

Leave a Testimonial Here.

⌨️ Happy Coding!
Erik Frits

Join Newsletter

📩 You will be added to Revit API Newsletter

Join Us!

which is already read by 7200+ people!

Last Chance To Claim LIFETIME ACCESS. [~40 Seats left]