How to find text with PropertyWizard

You can use the instr() function to find text in a PropertyWizard function. It finds the position of one piece of text inside another, and returns the character position of the first character of the found text, or -1 if the text isn’t found.

So, say we want to find all the rooms where the room’s Name contains “Bedroom”, such as “Main Bedroom”, ” Bedroom 2″, etc. The formula for that would be:

instr(Name, "Bedroom")

To turn that into a true/false value, you could use:

instr(Name, "Bedroom") != -1

This checks whether the instr result is not equal to (!=) minus 1. It will return true if the Name contains “Bedroom” and false otherwise – you can put this true/false result directly into a Yes/No parameter.

Alternatively, if you wanted to get a text value as the result:

if(instr(Name, "Bedroom") != -1 , "Bedroom", "Not A Bedroom")

Here are the three formulas in PropertyWizard. I’ve made three new project parameters as target properties:

PropertyWizard Formulas window showing three formulas using instr to find the text "Bedroom"
The three instr formulas

And here is the result in a Room schedule:

Revit Room Schedule showing the results of using the three instr formulas to find the text "Bedroom"
Room schedule showing the results of the instr formulas

Notice how instr is case-sensitive – the formula has not found room number 4, because its name is “bedroom” not “Bedroom”. I will cover case-changing formulas in a future post, when the next version of PropertyWizard is live.

You can download the formulas XML here to import into your own project – you will need to change the target properties to suit your project:

How to generate Level Codes in Revit with PropertyWizard

It’s useful if your Revit Levels have a Level Code as well as a Level Name. That way, you can use the Level Code in your formulas for door numbers, room numbers, etc:

Level NameLevel Code
Level 000
Level 101
Level 202
etc.etc.
Level Names and Level Codes

You could type the level codes in, level by level. But if you have PropertyWizard, you can just generate them. This post walks through a couple of different ways of generating the level codes from the level names. And on the way, it explains two of the text functions in PropertyWizard: substr() and strlen().

Method 1: Simple substr()

The substr() function extracts a number of characters from a text value. It has three inputs:

substr(<text value>, <start character>, <number of characters>)

The <text value> is the text you want to extract characters from. In this case it will be the value of the Level’s Name parameter.

The <start character> is the character number to start at, with the first character in the text being number 0. In these level names, the digit is character number 6.

The <number of characters> is how many characters you want to extract. In this simple case, you would use 1 to extract just one digit.

So the substr will look like this:

substr(Name, 6, 1)

Finally, to generate the full level code, you prefix the extracted digit with a “0”:

"0" + substr(Name, 6, 1)
PropetyWizard Formula Window showing simple Level Code formula using substr

Method 2: substr() with strlen()

Method 1 will work for levels up to 9, but will fail with two-digit levels, 10 and up. How can you fix that?

Since the two-digit levels are longer than the one-digit ones, you can use an if() function and a strlen() function to choose between two different options.

The strlen() function simply returns the number of characters in the input text value:

strlen(<text value>)

The if() function chooses between two alternatives. It has three inputs:

if(<test>, <output if true>, <output if false>)

The <test> is an expression that evaluates to true or false. In this case, if the level name is 7 characters long you know that it is a one-digit level. Otherwise it will be a two-digit level:

if(strlen(Name) == 7, <one-digit level>, <two-digit level>)

If it is a one-digit level, you would use the function from Method 1, but if it is a two-digit level, you would just need something like:

substr(Name, 6, 2)

So the completed formula will be something like this:

if(strlen(Name) == 7, "0" + substr(Name, 6, 1), substr(Name, 6, 2))
PropetyWizard Formula Window showing simple Level Code formula using strlen and substr