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 Name | Level Code |
Level 0 | 00 |
Level 1 | 01 |
Level 2 | 02 |
etc. | etc. |
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)
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))