Revit Families 103 – Formula Basics
by Tim Alatorre

Posted on October 21, 2009

Revit, Revit 2010, Revit 2011, Revit 2012, Revit Families, tips
Update: 4/12/11 for Revit 2012 and added more examples.
I love formulas, they let you do some really fun things. The formula I mentioned in my last post calculates the overall width of a family taking into account if the family has one or two loops toggled to be visible. Formulas let you create a family that is truly flexible and has a lot of built in intelligence and a few safeguards. They can also make using the family a lot easier to use by maintaining relationships between elements or calculating details about the family like area, volume, etc.
I do some pretty advanced stuff with formulas, but we need to get the basics under our belt first. Most of this post is from the Revit Help files. To save you the trouble of looking it up, I’m putting it here.
Keep in mind that Revit is aware of units. So to avoid getting an inconsistent units error remember to divide and multiply when appropriate.
For example, these are correct formula:
(Length_A * Length_B) = Area_C
(Length_A * Length_B)/1 = Length_C
Basic opperators:
+  Add: 15′ + 0′ 6″ + Length  sin  Sine: sin(75) 
–  Subtract: 1′ 2″ – Width  cos  Cosine: cos(75) 
*  Multiply: Length * Width  tan  Tangent: tan(75) 
/  Divide: Length / 8  asin  Arcsine: asin(75) 
^  Exponent: x^y, x raised to the y power  acos  Arccosine: acos(75) 
log  Logarithm: log (100)  atan  Arctangent: atan(75) 
sqrt  Square root: sqrt(64), square root of 64 = 8  
exp  E raised to an x power: exp(2)  
abs  Absolute Value: abs(2), will return 2 


pi  pi: pi() * (Radius ^ 2), the formula for Circumference 

Conditional Statements
A conditional statement uses this structure:
IF (<condition>, <resultiftrue>, <resultiffalse>)
This means that the values entered for the parameter depend on whether the condition is satisfied (true) or not satisfied (false). If the condition is true, the software returns the true value. If the condition is false, it returns the false value.
Supported Conditional Operators
<  Less Than 
>  Greater Than 
=  Equal to 
/  Divide: Length / 8 
AND  Both statements are true 
OR  One of the statements is true 
NOT  Statement is false 
Conditional statements can contain numeric values, numeric parameter names, and Yes/No parameters.
Currently, <= and >= are not implemented. To express such a comparison, you can use a logical NOT. For example, a<=b can be entered as NOT(a>b). For more information see “Revit Families 402 – Greater Than or Equal To“
Sample Conditional Statements
Simple IF Statement
IF (Length < 30′, 2′ 6″, 4′)
Formula That Returns Strings
IF (Length > 30′, “This thing is tall”, “This thing is short”)
Using logical AND
IF ( AND (x = 1 , y = 2), 8 , 3 )
This will return <true> if both x=1 and y=2, else <false>
Using logical OR
IF ( OR ( A = 1 , B = 3 ) , 8 , 3 )
This will return <true> if either A=1 or B=3, else <false>
Nested IF statements
IF ( Length < 10′ , 1′ , IF ( Length < 20′ , 2′ , IF ( Length < 30′ , 3′ , 4′ ) ) )
Returns 1′0″ if Length<10′0″, 2′0″ if Length<20′0″, 3′0″ if Length<30′0″ and 4′0″ if Length>30′0″
IF with Yes/No condition
Length > 10
(Note that both the condition and the results are implied.)
Returns checked box <true> if Length > 10
NOT with Yes/No condition
not(myCheckbox)
Returns checked box (<true>) of Yes/No parameter “myCheckbox” is unchecked, and it returns <false> if “myCheckbox” is checked.
Rounding
Prior to Revit 2012 the only way to round numbers was to pass a number through an integer parameter. The integer parameter always rounds to the nearest whole number with the standard mathematical rounding rules of:
Down > for fractions of 0.0 to 0.49 and 0.5 to 0.99
Up > for fractions of 0.05 to 0.99 and 0.49 to 0.0
As of Revit 2012 we now have three additional functions to use!!
Note that “x” is unitless
Round(x)
Rounds to the nearest whole number per the standard rules mentioned above.
round (1.1) = 1
round (1.5) = 2
round (1.7) = 2
round (1.1) = 1
round (1.5) = 1
round (1.7) = 2
Roundup(x)
Rounds to the largest whole number greater than or equal to “x”.
round (1.0) = 1
round (1.5) = 2
round (1.6) = 2
round (1.0) = 1
round (1.5) = 1
round (1.6) = 1
Rounddown(x)
Rounds to the smallest whole number less than or equal to “x”.
round (1.0) = 1
round (1.5) = 1
round (1.6) = 1
round (1.0) = 1
round (1.5) = 2
round (1.6) = 2
Some Extra Stuff
 Revit allows you to use integers, decimals, fractional values, and parameter names in formulas. You can enter dimensions in feet and inches just like you do in dimension strings. Remember that parameter names are case sensitive.
 You can enter a value in a formula essentially locking it across all types. This is an alternative to locking the dimension in the model.
 Instance and Type parameters can not be used in the same formula.
 It’s a good idea to not name your parameters with any of the mathematical operators in this list.
For a little advanced Boolean action check out this post!
http://whosafraidofthebigbadbim.blogspot.com/20…
hey
I'm trying to add a rebar family with little bit more than just a shape.
example having an L bar shape with set of rule that is A Length must be all the time greater than B length
i have tried
1.A>B did not work
2. IF (A>B, true, False) did not work
3. (A>B, true) did not work
any assistant will be much appreciated
That's a great question Faekk, and something I've wanted to do many times. Revit formulas don't let you directly do validation of entries, but you can create a default value if the number is out of range.
WHAT REVIT DOESN'T DO: Return an error or not allow A to be bigger than B
WHAT REVIT WILL DO: If A is bigger than B then default to C
To make this work you would need two parameters that the user inputs, A and B. Then you create one more parameter for the actual value of A, we'll call this Aa. Aa is what you assign to the model geometry. The formula for Aa would be:
IF (A > B, A, C)
What this means is if A is bigger than B then Aa=A, otherwise it equals the default value you set, C.
I know this is a very convoluted way to accomplish this. I hope in a future release of Revit they implement some basic validation rules. Until then we all get to be creative.
[…] – Data Validation Dec 142009 Leave aComment As I mentioned in a follow up comment to Revit Families 103 – Formula Basics, Revit still doesn’t allow you to do data validation on values or formulas in families or […]
sloarch,
I have tried and tried but can not get your recomendation to work.
Can you eloborate a little more on the parameters ect.
Aa is assigned to the model geometry .. is the slabs to contain the rebar shape?
If so where/who do add the parameter?
MrED
MrEd,
Have you read my post on data validation in Revit? https://www.sloarch.com/2009/12/revitfamilies4… I go into more detail, but I don't guarantee that it's any easier to understand.
Can you give me more information about what you are trying to do? Where are you running into problems?
I am trying to achieve the same a Faekk..
Open up the L.rfa Reber Shape family from the RST 2010 > Metric Library > Structural > Reber Shapes folder.
I am trying set length B on the Reber Shape so that it is never less then the Length of A, Using the formula you have stated.
IE. IF(B>A,B,A) translated if side B is greater than A, then use B, else B = A.
Hope this clears up my query.
Unfortunately I don't have access to Revit Structure or the rebar shape at the moment, however I think I understand.
You don't need to change the model at all, everything can be done in the Family Types dialog. In the Family Types dialog create a new Parameter for “B”, call it “Buser”. Make sure it is the same Type of Parameter as “B” and match the Instance/Type switch to the existing “B” parameter.
Now add this formula to “B”:
if(Buser > A, Buser, A)
Now to change the value of “B” in the model you enter the value into “Buser.”
Hope this helps.
Unfortunately I can not get it to work and it seems that this statement is the casue “Family parameters cannot be added to Rebar Shape Families.”
I found this on the Autodesk website, relating to RST 2009 but it seems it still applies to RST 2010.
I think you are referring to this thread?
http://discussion.autodesk.com/forums/message.j…
That is unfortunate. I haven't worked in RST, but it appears that the Rebar functionality still needs some significant improvements.
Alright sloarch,
I hope you can help me with this… I've got a post that consists of 2 families (inner and outer). First, I would like to have limits on the extension lengths (the post height must be within range, or hieght cannot be less than x or greater than y… whichever makes more sense). Thanks for any help.
It looks like you already posted a link to some info that may help with this… sorry.
No worries, thanks for the question. What you mention here is fairly easy to do, and I outline a few methods in my post on data validation.
https://www.sloarch.com/2009/12/revitfamilies4…
Alright sloarch,
I hope you can help me with this… I've got a post that consists of 2 families (inner and outer). First, I would like to have limits on the extension lengths (the post height must be within range, or hieght cannot be less than x or greater than y… whichever makes more sense). Thanks for any help.
It looks like you already posted a link to some info that may help with this… sorry.
No worries, thanks for the question. What you mention here is fairly easy to do, and I outline a few methods in my post on data validation.
https://www.sloarch.com/2009/12/revitfamilies4…
[…] discussed in “Revit Families 103 – Formula Basics” there is no native function in Revit for Greater Than or Equal to (>=) and it’s […]
[…] to reading this post we recommend reading “Revit Families 103 – Formula Basics” to get the complete overview of all the basic operations allowed in Revit […]
[…] El sitio que mas me gusta es el Revitforum.org donde hay ejemplos del uso de estas formulas, el sloarch.com igual que revitforum.org tiene ejemplos prácticos y por otra parte esta la wikihelp de […]