How to filter Revit elements using an if() function

A PropertyWizard formula usually affects all the elements in the category you’ve selected. But what if you only want to affect a subset of the elements?

You can do this with an if() function in this form:

if(<filter criteria>, <your formula>, <target parameter>)

The <filter criteria> is where you choose which elements to affect, and the <target parameter> is the name of the formula’s target parameter. The <your formula> is where you put the formula that you want to apply to the selected elements.

For example, to affect only elements on Level 1, your filter criteria would be something like this:

if(Level.Name == "Level 1", <your formula>, <target parameter>) 
PropertyWizard Formula window showing a formula for the category 'Doors', Target Property is 'DWD-Test' and the Formula text is 'if(Level.Name == "Level 1", "This door is on Level1", [DWD-Test])'

How does this work?

This technique works because, when PropertyWizard evaluates the if() function for each element, it starts by evaluating the <filter criteria>. If that returns ‘true’, meaning that the element passes the filter, the if() function returns the value of <your formula>.

On the other hand, if the element doesn’t pass the filter, the if() function will return the value of the <target parameter>, and since that is equal to the actual <target parameter>, the formula has no effect.

This leaves the other elements uncontrolled

You will have noticed that, normally, if you change the value of a parameter that’s controlled by a formula, PropertyWizard immediately changes it back.

However, if you use this technique, the elements that don’t pass the filter aren’t controlled by the formula. So you are free to edit the value of the target parameter on these uncontrolled elements.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.