From the course: Revit: Parametric Curvature in the Family Editor

Introducing formulas - Revit Tutorial

From the course: Revit: Parametric Curvature in the Family Editor

Start my 1-month free trial

Introducing formulas

- [Instructor] As useful and as powerful as it is to create labeled dimensions and parameters that can drive family behavior, it becomes even more powerful and more useful when we start to compile formulas and rules that can actually take into account the values of other parameters and other settings to create more complex relationships and values. So what I'm talking about is formulas. Revit supports all sorts of mathematical formulas, Trigonomic Formulas, Logical Formulas, If Then Statements, and a variety of things that we can use in our families to make them more complex, more robust, and more powerful. So let's start with where you would input this information. Well in the Family Editor, it's in the Family Types Dialogue. So when we go to Family Types, next to each parameter that you define you will see a formula field and in that formula field you can type in any valid formula. Now it could be as simple as just some basic arithmetic. So I could ask Revit to do the calculation for me by typing in two numbers. Now when you do that, you'll see that the parameter will become read-only and it will just do the calculation for you of this value. Now, that's useful but that kind of freezes that value at a certain number so more powerful is if you take other parameters in your file and incorporate those into the formula. So instead of saying four plus seven, maybe I'll say something like D plus seven. And now it will arrive at the same result of 11 but the difference is it's now become parametric so if we change the value of four to something else, it will redo the calculation for the parameter of W. Now that's just using simple arithmetic. We can use all sorts of syntax in our formula fields. We can use Addition, Subtraction, Multiplication. We can use Trigonometry, Logarithms, complex If, Then, and And Logical Statements, and so on. So, let me cancel out of here and let me show you where you find exactly what syntax is supported, exactly what kinds of formulas can we use. Well the best place to start is the Revit Help System. So if you just go to the Help Menu in the upper right hand corner and choose Help, it will launch the Help System in your default web browser. Now when you get here, you can enter a keyword and to get right to what formulas are supported, just type in the word formulas here and it will show you several articles that contain that keyword. Now, there's some formula examples here. There's some general information on formulas here. I'm going to skip right to this one, Valid Formula Syntax and Abbreviations. This will give you a nice tidy list of all of the formula types that are supported and what format you put them in. So for simple arithmetic, you're going to use the plus, minus, multiplication signs. For Trigonometry, you're going to write out the word sine or cosine or tangent. For Pi you're going to us the letters PI and so on. So all the formats are listed there. There's a little bit here about different unit format issues as well, because the units are very important when you're working in formulas. You can do rounding functions as you can see down there toward the bottom. And then if you scroll all the way down, there is another related concept link that we could click on, conditional statements. So if you want to use logic formulas in your family content, then you can use If Statements, And Statements, Or Statements, and you can even nest them together to create even more complex statements. So the way these work is you set up a condition where you say, you know, if this is true, do A and if it's not true, do B, right? And so you can kind of branch the decision making in your family based on certain criteria. So, you know, if an object is smaller than a certain size you can set it one way and if it's bigger than a certain size, you can set it another way. Or, any number of things that you can imagine doing by setting up those logical statements. Now another great resource for learning about formulas, their syntax, and some nice examples is out on the Revit Forum. So Revit Forum is a website that's been around for many years and this post is actually several years old but still quite pertinent to today. It was posted by Claus Monkholm, the Administrator of this website, and it's got several examples of all the different types of formulas that you can input in Revit and the examples are in Revit syntax so that you type them in correctly. So there's lots of things to scroll through here, including this nice little cheat sheet here on Trigonometry. Now, a couple years back in one of the books that I wrote, I took this information on the Trigonometry cheat sheet and made a more graphical version of it that I included in the book and I've provided a PDF of that cheat sheet for you in the exercise files and I was given permission by Claus to go ahead and provide that information both in my book and to you in the exercise files here. So if you have access to the exercise files, then you can just print this page out. This is a one page cheat sheet that summarizes all those Trigonometry function and the reason that I provided this separately is because we're going to do a lot with the Trigonometry functions in the coming videos and so it's nice to have this handy. So what this does is it just highlights in bold the two known pieces of information and then based on those, shows you all the other things that you can derive from that. So the way that the Trigonometry functions work is you need to know two things and then from those two things, you can find out anything else about a triangle. So, if you know two sides, you can find out the third side, or the angles, or if you know one of the angles and one of the sides, you can find out the other things. So, you just look at which two things you know based on the diagrams and then from that, these are the formulas in Revit syntax that you can plug into that formula field to calculate the third or the fourth piece of information. Now these letters can be substituted with parameter names. So A and B don't have to be A and B. You can put in length or width or capital L or whatever you named the parameter so that it's actually calculating the values off of your real Revit parameter values. So let's summarize all this with a few tips that you want to keep in mind when you're inputting formulas into your family content. So the first thing is you can use fixed values, of course, you know, just type in the numbers. But it's even more powerful when you input parameters. So, rather than just doing five plus two, you can do length plus two or you can even do length divided by width, right? So now you're using other parameters in your family to calculate the values rather than having to put in the static fixed values. Formulas are case sensitive. So, this, this, and this, would be treated as three separate parameters by Revit. So if you don't input it in the exact correct spelling and case that you're parameter name is in, then the formula won't work and it'll just generate an error saying that it doesn't recognize that parameter name. You want to pay close attention to the units of each of your parameters. So, if you have a value that's formatted as length it might look like that and area, it might look like that. If it's an angle, it would look like that and if it was just a number, it might look like that. So, each of these is 49 but because they're in different unit formats, they look quite different and if you tried to input a length value in an area field, it will fail. If you tried to put an area value in an angle field, it will fail. So when you're writing your formulas, you have to make sure the units of those parameters are compatible with one another and if they're not, you might have to actually do some conversions. So for example, in order to take an area value and use it in a length field, you might have to divide it by one and that would remove the square unit and turn it into just a single unit, as an example. So, you have to think about those things and keep that in mind when you're writing your formula syntax. And also, pay close attention to the parentheses. If you're just doing a simple formula where you're adding two values together, it's not a big deal. But as the formulas get more complex and more values are involved, and I'm just using number values here, but each one of these numbers could be a parameter, that and that and that and that are all the same numbers, or all the same parameters but as you can see, they generate four completely different results, just simply based on where the parentheses are. So, parentheses grouping allows you to tell Revit which items in the formula to evaluate first and then once it's got that number use it in the next step of the calculation. So it's almost like doing subtotals. So you want to pay close attention to those as well and if you're missing a parentheses somewhere, or if you drop a unit, sometimes the error messages are very cryptic and Revit won't give you a lot of information on how to fix it so you just have to pay really close attention and troubleshoot as best you can. So, in the next several videos, we're going to look at some practical, hands-on examples of using formulas to make your family content even more robust.

Contents