Formulas / Math in Revit
Formulas are endless and can be used for any and everything. The limit is your knowledge of math and syntax and the imagination to apply these formulas to family elements. They can help drive dimensions (width, height, length), integers. The only parameter you cannot use a formula for is ‘count’.
Formula Syntax
The below table outlines the formula syntax, a sample and a description.
Type | Syntax | Sample Use | Description |
|---|---|---|---|
Addition | + | Rough Height = Height + Undercut + Frame Width |
|
Subtraction | - | Sill Height = Head Height - Height |
|
Multiplication | * | Width = Panel Count * Panel Width |
|
Division | / | Count = Width / Spacing |
|
Equals | = | 1=1 |
|
Less Than | < | 1<2 |
|
Greater Than | > | 2>1 |
|
Exponential | ^ | Area = Width^2 | where Width is raised to the power of 2. The 2 could also be a parameter integer. |
Logarithm | log | 3 = log1000 | The logarithm of a number to a given base is the exponent to which the base must be raised in order to produce that number. For example, the logarithm of 1000 to base 10 is 3, because three factors of 10 must be multiplied to yield a thousand: 10 × 10 × 10 equals 1000 |
Natural Logarithm | ln() | ln(x*y) = ln*x + ln*y | Logarithm of a number to the base value of mathematical constant e. These are used to solve for the half-life, decay constant, or unknown time in exponential decay problems. They are important in many branches of mathematics and scientific disciplines, and are used in finance to solve problems involving compound interest. |
Square Root | sqrt | Hypotenuse = sqrt((a^2 + b^2)) | This is especially useful in trigonometry and calculating lengths. |
Trigonometry | |||
Sine | sin(x) | Hypotenuse * sin(Angle) = Opposite | You know the Hypotenuse and the Angle and want to find the Opposite Side. |
Cosine | cos(x) | Hypotenuse * cos(Angle) = Adjacent | You know the Hypotenuse and the Angle and want to find the Adjacent Side. |
Tangent | tan(x) | Adjacent * tan(Angle) = Opposite | You know the Adjacent and the Angle and want to find the Opposite Side. |
Arcsine | asin(x) | asin((Opposite/Hypotenuse)) = Angle | You know the Opposite Side and Hypotenuse and want to fine the Angle. |
Arccosine | acos(x) | acos((Adjacent/Hypotenuse)) = Angle | You know the Adjacent Side and Hypotenuse and want to fine the Angle. |
Arctangent | atan(x) | atan((Opposite/Adjacent)) = Angle | You know the Opposite Side and Adjacent Side and want to fine the Angle. |
Exponential | exp(x) | exp(3) | Mathematical constant e (Euler’s Number = approx. 2.7) raised to the power of x. |
Absolute Value | abs | 2 = abs(-2) | This is useful when your value cannot be negative. |
Pi | pi() | Circle Area = pi() * (Radius^2) | π is a mathematical constant and is the ratio of a circles circumference to its diameter. |
Round Closest | round(x) | round(3.1) = 3 | The round function returns a value rounded to the nearest whole number. It doesn't take into consideration rounding direction. |
Round Up | roundup(x) | roundup(3.1) = 4 | This is useful when calculating spacing and you don’t want the value to be smaller than the minimum. |
Round Down | rounddown(x) | rounddown(3.7) = 3 | This will return the smallest integer value less than or equal to the x. |
Text | “Some Text” | CreatedBy_ANZRS = “Xrev Pty Ltd - Chris Price” | Use quotation marks in Text parameter formulas to lock the parameter for editing and have a fixed value. |
Conditional Statements | |||
Conditional statements are especially useful for validation of parameter values. For example,
| |||
IF Condition | if(x,a,b) | if(Condition, ResultTrue, ResultFalse) | In this example its shown how you may validate an array formula to not be less than 2, given an array needs at least 2 elements to exist. |
AND Condition | AND() | and(Height=1200, Width=1200) | In this case, if Height and Width both equalled 1200 this statement would be considered True. |
OR Condition | OR() | or(Height=1200, Width=1200) | In this case, if either Height and Width equalled 1200 this statement would be considered True. |
NOT Condition | NOT() | not(Height>Width) | In this case, if Height is not greater than Width this statement would be True. |
Yes/No Parameter | Visibility = | Height>Width | With a Yes/No parameter the IF condition is implied. If I wanted to use an if statement here it would be as per the second example. The 3rd & 4th examples show how you can force these values to be locked. |
Advanced Conditional Statements | |||
The below example shows how multiple conditional statements are used in conjunction with each other. In this case there are 4 distinct conditions which have been colour coded to make it clearer where they are separated (at the commas). Height = | |||
Formulas/Calculations within Temporary Dimensions
Within any temporary dimension value within Revit you can use formulas. Simply Left Click on the dimension value to edit it, then type = followed by the formula and affectively you have a built-in calculator.
Family Type Category Dropdown Lists with Formulas
When using a Family Type parameter for a particular Family Category in your Family, you will note there is no obvious way to refer to the Family Type value.
In the below example the following parameters are Family Type parameters;
PanelB1 Type
PanelB2 Type
Fixed Pane
By setting “Fixed Pane” to the dropdown item that is required for the condition instead of referring to the parameter value, we refer to one parameter equalling the same value of another parameter.
Resolving Inconsistent Units
Occasionally you may receive an inconsistent units error. In order to resolve this you need to investigate the units being used on each value.
For instance, if you have 2 separate millimetre values you and you are multiplying them together, the final value will be mm². But if the units of the result parameter are millimetres, Revit will complain. The solution is to then divide by 1mm. This will bring the units back to millimetres.
There is more information here.
Utilise tools like Notepad++
Having trouble getting the correct number of brackets? Use Notepad++ as when you highlight a close out bracket, the corresponding bracket will also highlight.