How to use the if() function in PropertyWizard for Revit

PropertyWizard’s if() function works in the same way as the native Revit one, which is described in the online Help here:

http://help.autodesk.com/view/RVT/2022/ENU/?guid=GUID-A0FA7A2C-9C1D-40F3-A808-73CD0A4A3F20

The syntax is:

if(<condition>, <result-if-true>, <result-if-false>)

When PropertyWizard evaluates an if() function, it starts with the <condition>. For example in this formula:

if(Level.Name == "Level 0", "It's Level 0!", "It's some other Level!")

It will start by evaluating this expression:

Level.Name == "Level 0"

In PropertyWizard, the double-equals-sign ‘==’ means ‘is equal to’. So the value of the expression will be ‘true’ if the element’s Level’s Name is equal to “Level 0” and ‘false’ otherwise.

PropertyWizard uses the value of the <condition> to decide which value to return from the if() as a whole. If the <condition> evaluates to ‘true’, it returns the <result-if-true>, and if the <condition> is ‘false’ it returns the <result-if-false>.

PropertyWizard Formula window showing an if() function

Nested if() functions

You can nest if() functions to code more complex logic. For example, you can check whether the level name is “Level 0”, “Level 1” or some other Level like this:

if(Level.Name == "Level 0", "It's Level 0!", if(Level.Name == "Level 1", "It's Level 1!", "It's some other Level!")) 

Here, the outer if() has the same <condition> as before, and the same <result-if-true>. But the <result-if-false> is a nested if() function:

if(Level.Name == "Level 1", "It's Level 1!", "It's some other Level!") 

So when the outer if()’s <condition> returns ‘false’, PropertyWizard goes on to evaluate this inner if() and decide whether the level name is “Level 1” or not.

You can put a nested if into the <result-if-true> as well., and you can have multiple layers of nesting. With complex nesting, it can get tricky to put all the commas and parentheses in the right place: I tend to start small and evaluate each piece individually, and then gradually assemble the formula. It is easier to find errors if you make small changes and test as you go along.

Leave a Comment

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.