Formulas / Math in Revit

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

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)
Circumference = pi() * (Radius * 2)
Circumference = pi() * (Diameter)

π is a mathematical constant and is the ratio of a circles circumference to its diameter.

Round Closest

round(x)

round(3.1) = 3
round(3.5) = 4

Round to a Increment other than 1:
round(Value/Increment)*Increment
round(Value/5)*5 would be to the nearest 5.

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
roundup((Width/Spacing)) = Count

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,

  • There may be a minimum or maximum value that you want to limit your parameter values to, or

  • You may want to turn certain elements On/Off under particular conditions, or

  • You may have a list of parameter values that each item should be, and don’t want to allow just any value to be input.

IF Condition

if(x,a,b)

if(Condition, ResultTrue, ResultFalse)
Array Validation:
if(ArrayCount<2, 2, ArrayCount)

Check with Text Result:
if(Length<900, “Too Narrow”, “OK”)

Range of Values (nested IF statements):
if(User Value < Minimum Value, Minimum Value, if(User Value > Maximum Value, Maximum Value, User Value))

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
if(Height>Width, 1=1, 1=2)
1=1
1=2

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 =
if(and(Transom Count Validation = 0, not(Equal Transom Spacing)), Head Width + Sill Width + PanelA Height,
if(and(Transom Count Validation = 1, not(Equal Transom Spacing)), Head Width + Sill Width + (1 * Transom Width) + PanelA Height + PanelB Height,
if(and(Transom Count Validation = 2, not(Equal Transom Spacing)), Head Width + Sill Width + (2 * Transom Width) + PanelA Height + PanelB Height + PanelC Height,
Height_ANZRS)))


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.

Temporary Dimension Formula

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.

Sample of Brackets Highlighting and how to write long condition lists

Related articles