You are on page 1of 14

eTip

Revit Family Formula Tips and Tricks


When creating formulas in a family it is helpful to have a go to list of examples. Use these as a start point and build up on
them.

IF Statement (returns a Numeric value)


IF (Length < 50, 3, 5)
If the Length parameter is less than 50 then the current parameter value is set to 3.

If this is not true (the Length parameter is more than 50), then the current parameter value is set to 5.

IF Statement (returns a String value)


IF (Height > 50, “This item is tall”, “This item is short”)
If the Height parameter is greater than 50 then the current parameter value will be set to the string value of This item is tall.

However, if this is not true (the Height parameter is less than 50) then the current parameter value will be set to the string
value of This item is short.
eTip

Nested IF Statements
Here if an If statement is correct a value is set, but if it is not correct it looks at another If statement to see if that is correct, if it
is it sets a value, if not it goes to the next If statement, and so on.

IF (Length < 50, 10 , IF (Length < 60, 15, IF (Length < 70, 20, 25 ) ) )

If the Length parameter has a value less than 50, then the current parameter value is set to 10.

However, if the is not true it checks the next If statement, so if the Length parameter has a value less than 60 (but greater than
50 due to the previous statement), then the current parameter value is set to 15.

However, if the is not true it checks the next If statement, so if the Length parameter has a value less than 70 (but greater than
60 due to the previous statement), then the current parameter value is set to 20,

If this is not true then the current parameter value is set to 25.
eTip

Using Yes/No Conditions


If we have setup a parameter as having a Type Of Parameter of Yes/No,

then we can apply formulas to it that will return Yes (ticked box) if the condition is True or No (unticked box) if the condition is
False. We do not use the If statement, Revit checks to see if the given formula is true or false itself.

Length > 50

If the Length parameter is greater than 50 then the statement is true and the Yes/No check box is checked (ticked).

If the Length parameter is not greater than 50 then the statement is false and the Yes/No check box is NOT checked (ticked).

IF OR Statement

IF (OR (Length = 10 , Width = 20 ) , 10 , 30)

If either the Length = 10 or Width = 20 then the current parameter value will be set to 10.
eTip

However, if Length does not = 10 and Width does not = 20 then the current parameter value will be set to 30.

IF AND Statement

IF (AND (Length = 10, Width = 20), 30, 50)

If Length = 10 and Width = 20 then the current parameter value will be set to 30.

However, if either Length does not = 10, or Width does not = 20 then the current parameter value will be set to 50.
eTip

Some Formula Tricks of the Trade

This or That only with a Yes/No parameters

By specifing that Metal can not be true while Timber is true, the user can only specify one of the two materials. They both
cannot be checked at the same time. This can be used for visibility where a left or right access panel may be required but never
both.

Yes/No Drives Tag


In this example an exit sign needs to be tagged with the text "EMERGENCY" or "EXIT".

A Yes/No, Graphics parameter is created called "EMERGENCY".

A Shared text parameter (Exit Type) is added with a formula to determine if the Exit sign is near a stairway.
eTip

If (EMERGENCY, "EMERGENCY","EXIT")

If the parameter of EMERGENCY is true, return the text "EMERGENCY",

if false return the text "EXIT".

Create a tag that references the shared parameter to show "EMERGENCY" or "EXIT".
eTip

Pick One and Only One


Here the condition number will allow only one parameter to be true in a list. Associated with a type, you could control a
number of things simply back picking the correct type.

EXAMPLE ONE:
In this example we want to create a Paint Finish, where the user can choose from five (5) different colors.

Create a Type parameter - An Integer, Other parameter, which is called "PAINT FINISH".

Create a Type parameter – an Integer, Other parameter, which is called "PAINT COLOR CHECK".

Finally, create a series of Type parameters - a Yes/NO, Other parameters, which are called “1 IS RED”, “2 IS YELLOW”, ”3 IS
GREEN”, “4 IS BLUE”, “5 IS PURPLE”.

Then add the following formula to the Paint Color Check parameter:

=if(or(Paint Finish = 0,Paint Finish > 5),1,Paint Finish)


eTip

This checks to see if the Paint Finish value is set to 0, or greater than 5, if it is it will set the Paint Color Check value to 1, if it is
not (it is between 1 and 5), then it will set the Paint Color Check to the appropriate value of 1, 2, 3, 4, or 5.

We also need to set the corresponding colors to switch on or off depending on what the Paint Color Check value is, this is done
with a simple formula of:

=Paint Color Check = 5 for the 5 is PURPLE parameters etc.

Because these are Yes/No, they will only switch On if their value is true.

EXAMPLE TWO:
In this example we want to work out the Glass area of a selected window. Each window has its own formula for working out
the glass area. There are a total of three (3) windows of completely different glass areas.

Create a Type parameter - An Other, Integer parameter, which is called "WINDOW TYPE".

Create a Type parameter - An Other, Integer parameter, which is called "WINDOW TYPE CHECK".
eTip

Back in the Family Types dialog box give the Window Type Check parameter the following formula:

=if(or(Window Type = 0, Window Type > 3), 1, Window Type)

This checks to see if the Window Type value is set to 0, or greater than 3, if it is it will set the Window Type Check value to 1, if
it is not (it is between 1 and 3), then it will set the Window Type Check to the appropriate value of 1, 2, or 3.

Now we need some overall Window Sizes:

Create a Type parameter – A Dimension, Length parameter, which is called “WIDTH”.

Repeat the above step for one more parameter called “HEIGHT”. Do not forget to type in values for each of these, in this
example Width = 2000, while Height = 1000.

Create a Type parameter – A Text, Area parameter, which is called "1 IS PLAIN SQUARE WINDOW".
eTip

Repeat the above step for three more parameters: "2 IS SQUARE WINDOW WITH WOOD PANELS”, "3 IS SQUARE WINDOW
WITH LOUVRES" and “GLASS AREA”.

We now need to add formulas that calculate the area of glass for each window type:

For “3 is Square Window With Louvres” add the following formula:


=(Height * Width / 3) * 2

For “2 is Square Window With Wood Panels” add the following formula:
=(Height * Width) / 2

For “1 is Plain Square Window” add the following formula:


=(Height * Width)

Note that the resultant area is in Square Meters, this is because they are the default in Manage > Settings > Project Units, you
can change them to Square Millimetres and the Parameters will update accordingly.
eTip

We now need to add a formula so that the correct area is shown for the selected Window Type:

= if(Window Type Check = 1, [1 is Plain Square Window], if(Window Type Check = 2, [2 is Square Window With Wood Panels],
[3 is Square Window With Louvres]))

Here the formula is checking to see what the Window Type Check value is, and then set the appropriate formula for calculating
the Glass Area.
eTip

Controlling Visibility
In this example we want to switch the Visibility of a solid On/Off depending on its Height.

Create a Type parameter – A Dimensions, Length parameter, which is called "HEIGHT".

Create a Type parameter – A Visibility, Yes/No parameter, which is called "CYLINDER".

Back in the Family Type dialog box:

Give the Height parameter a value of 400.

Give the Cylinder parameter a formula of


=(Height < 300)
This formula makes the Cylinder Visible if it is less than 300, and NOT Visible when the Height is not less than 300mm.
eTip

EXAMPLE TWO:

In this example we want to control the Visibility of a set of notes. The family contains three (3) sets of text (Notes), depending
on the value a different set of notes is Visible.

Create a Type parameter – An Other, Integer parameter, which is called "SHOW NOTE".

Create a Type parameter – An Other, Integer parameter, which is called "SHOW NOTE CHECK".

We need to add a formula to the Show Check Note Check parameter:


=if(or(Show Note = 0, Show Note > 3), 1 Show Note)

This checks to see if the Show Note value is set to 0, or greater than 3, if it is it will set the Show Note Check value to 1, if it is
not (it is between 1 and 3), then it will set the Show Note Check to the appropriate value of 1, 2, or 3.

Now we have to create parameters to control the Visibility of the each of the Notes.

Create a Type parameter – A Visibility, Yes/No parameter, which is called "TEXT NOTE 1".
eTip

Repeat the above step for “Text Note 2”, and “Text Note 3”.

Next, we need to add a formula to each of the Text Note Visibility parameters to control what is switched On/Off.

For the “Text Note 1” parameter, add the formula:


=Show Note Check = 1

Repeat for “Text Note 2”, and the “Text Note 3” parameter.

Now only the Note that is selected in the Show Note parameter is Visible.

Stop Accidental Changing Of Text


If you need some text to not change, put that text in the Formula column with quotes around it. It greys it out in the Value
column. This will help stop the “majority” of users from changing its value.

You might also like