Monday, January 23, 2012

Revit Family Formula Examples and Tricks

When creating formulas in a family it is helpful to have a go to list of examples. Here is mine.

IF Statement
IF (Length < 30′, 2′ 6″, 4′)    
     If the Length parameter is less than 30' x = 1 , y = 22'-6"
     If the Length parameter is greater than 30' this parameter will have a value of 4'-0"


IF that Returns a String
IF (Height > 30′, “This thing is tall”, “This thing is short”)     
     If the Height parameter is greater than 30' this parameter will return  This thing is tall
     If the Height parameter is less than 30' this parameter will return  This thing is short
Nested IF Statements
IF (Length < 35’, 2′ 6″ , IF (Length < 45′, 3′ , IF (Length < 55′, 5′, 8′ ) ) )
     If Length is less than 35', this parameter will have a value of 2'-6"
     If Length is between 35' and 45', this parameter will have a value of 3'
     If Length is between 45' and 55', this parameter will have a value of 5'
     If Length is greater than 55', this parameter will have a value of 8'

IF applied to a Yes/No condition
Length > 40' 

     If Length is greater than 40' the the statement is true and the Yes/No check box is checked
     If Length is 40' or less the statement is false and the Yes/No check box is NOT checked


IF OR
IF (OR (A = 1 , B = 3 ) , 10 , 5) 

     If A = 1 or B = 3 this parameter will have a value of 10
     If A is not = 1 and B is not = 3 this parameter will have a value of 5


IF AND
IF (AND (x = 1 , y = 2), 8 , 3 )
     

     If x = 1 and y = 2 this parameter will have a value of 8

     If x is not = 1 or y is not = 2 this parameter will have a value of 3


Some Formula Tricks of the Trade

This or That only with a Yes/No parameters






By specifing that metal can not be true while Wood is true the user can only specify one of the two materials. They both can not 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 "STAIR", "EXIT" or nothing. 


A Yes/No parameter is created called "STAIR".


A Shared text parameter is added with a formula to determine if the Exit sign is near a stairway.  if(STAIR, "STAIR","EXIT")


If the parameter of STAIR is true, return the text "STAIR", if false return the text "EXIT".


Create a tag that references the shared parameter to show "STAIR" or "EXiT" and don't tag exits signs that should have no text.


Pick One and Only One








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

"Don't Change Me Bro"



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 should stop the majority of users from changing its value.


Swapping Nested Families
In a bookcase family with a nested shelf family, follow these steps to add a parameter that will allow the user to switch from one type of shelf to another.


1. Open the original shelf family and save it as the second shelf option. Add something to make it different. 

2. Load this new shelf into the bookcase family, but do not place it.


3. In the Family Types dialog create a new Type parameter named “Swappable Shelf”. Make its discipline Common, its Type of Parameter and group it under Constraints.


4. When you select the Type of Parameter Revit will open the Select Category dialog. Pick Generic Models.
5.  Select the original shelf in the bookcase family now. In the Properties dialog, look for the Label parameter and change it to “Swappable Shelf”.
6.  In the Family Types dialog Create 2 shelf types, Shelf Type 1 and Shelf Type 2. Associate the swappable shelf parameter with the appropriate type.
7. Flex the family. Change the family type and verify that the shelf changes.

16 comments:

Erik said...

Nice post Todd. Great to see these all in one place.

tucker_arch said...

Another formula trick is to use the formula field to set yes/no parameters across types or permanatly.

Use 1=0 to turn off and 1=1 in the formula field. Hit apply to set across types, then delete the value, and finally hit apply again.

Leave the value in the formula field if you always want it set on or off.

Anonymous said...

My favorite new trick, which I picked up from a Taco family: You can create a drop down box with a fixed list of choices by using a family type parameter. Just load in a blank/dummy family, with a type corresponding to each list item.

Todd Shackelford said...

I like that too anonymous. I added an excerpt from an example I did earlier with a bookshelf that had swapable shelves.

Anonymous said...

Great tricks. I'm glad I came across your site as I have just started looking into formulas. I have 3 yes/no visibility parameters and can only have one visible at time. How can that be achieved?

Is it possible to control their visibility based on labels or other string parameters not contained within the family? For example, can it read the value of the sheet name or number?

I am trying to control the visibility of notes on a sheet and figured it was worth a try.

Thanks.

Teun said...

Thank you for your tips.
But can you please give a sreenshot or a simple family that shows that it is possible to return a string as a result of a formula? I really tried but it didn't work

IF that Returns a String
IF (Height > 30′, “This thing is tall”, “This thing is short”)
If the Height parameter is greater than 30' this parameter will return This thing is tall
If the Height parameter is less than 30' this parameter will return This thing is short

Thank you,
Teun.

Todd Shackelford said...

Teun,

See the new bit in the article called "Yes/No Drives Tag". I hope that helps.

Anonymous said...

But how would one set the visibility of a label within a tag based on a value of that label. For instance, tag all doors for a life safety plan, but only have the tag visible if the fire rating is greater than zero.

Max Holanda said...

Thank you! best regards from Brazil!




Anonymous said...

Do you know how to create a parameter that allows you to use a different formula for multiple family types?

What I am trying to do is calculate the glass area of my curtain panels. I have 3 types that all need a different formula for figuring out the glass area because certain areas need to be deducted depending on what is going on in the panel type. These panels are differentiated by using visibility settings, ie whether or not louvers is turned on or off, which affects the area.

Nick Fuller said...

Is it possible to nest a statement with the Not function so that the following would be true?

5 Yes/No Parameters
One will always be checked
Depending on which one is checked, the other 4 will thereby unchecked.

Thanks Shack! Hope you're well!

Nick Fuller said...

Is it possible to nest statements using the "Not" function so that the following would be true?

5 Yes/No Parameters
1 Will always be checked
4 Will always be unchecked

alaadin alsahli said...

is there a way to put condition that if i have parameter (Circuit Number) ="L1-1" then the return value is ="1-L1"
and if i have Circuit Number ="L2-1" then the return value is ="1-L2"
etc...
changing a value but another value

alaadin alsahli said...

if i have Circuit Number ="L1-1" then the return value is ="1-L1"
how can i do it

Saba Naaz said...

very nice blog

Saba Naaz said...

very nice blog