Join Paul F. Aubin for an in-depth discussion in this video Introducing formulas, part of Revit: Family Curves and Formulas.
As we begin creating more advanced families, I'd like to take a moment to talk to you about formulas. Revit has lots of formulas that we can add to the families and actually elsewhere in our project. So, let's take a quick look at what kinds of formulas are available. So, we'll start with basic mathematical formulas. We can, of course, do basic arithmetic, like addition, subtraction, multiplication, division. You can do logarithms, exponentiations, square roots, and even trigonometry. Now, since we're talking about curves, and many of the curves require three items, and three items make a triangle, you can hopefully see where I am going with this.
Most of the formulas that we're going to be using in the next several movies are actually going to be trigonomic formulas. So, we'll be looking at some resources that I have available to you to help you with those trigonometry formulas. In addition to those formulas, we also have a few other things that we can do like, conditional statements: if, then, and, or, not; you can do absolute values; you can use PI. And you can do various rounding if necessary in your formulas. So there's a lot of circumstances where you may need to do some of these things.
Now, as far as how to format all of this stuff, there's a resource in the help file that will help you with this. So you just go to the help menu in Revit, and it will take you right here. And the easiest way to get to the information on formulas is to click the search icon right here and type in formulas. And that will list out all of the topics that talk about formulas, and it's really these first couple items that you probably want to read through. The first is just a general kind of wrap up of the formula topics right here. So, these first few entires are about using formulas in a project environment, so you can actually use the equal sign and then type in a formula to do math when you're inputting data directly into the project.
What we're concerned with in the family editor is these two links right here. So valid formula syntax is definitely a must read here. So, I mentioned all the different kinds of formulas in the previous slide, but you can see here how they have to be formatted when you actually input them into Revit. So there's some information here and some examples down the bottom, here are examples for rounding and so on. If you go to the conditional statements link, if you are going to do any ifs, ands, ors, or nots, this gives you some examples on how to set up that syntax.
And then, there's also this link here that talks about errors and formulas, what some of the common causes for errors are. Either you have a mismatched on units is usually the most common type of error, so you are inputting a formula in an area field, but you divide two lengths together, so you end up with no unit. So, instead of multiplying, for example, which would give you area. So, sometimes you have to do some little tricks, like multiplying by one, or dividing by one, in order to add or remove the units, and so there's some discussion of that here in this help link.
So, I definitely recommend that you familiarize yourself with this, and again all you have to do is search for formulas, and it's the first couple links that come up. So now, where would we put in the formulas? So, this is noted in that help file that we were just in, but I just thought I would quickly show you where formulas get input in a family situation. I'm just in the generic model seed. It really doesn't matter which family you have open, so you could really open any family file for this because we're not going to save anything. But, you go to the family types dialogue here in the file, and the formula column is right here.
So next to any parameter, you can just simply click in this field and type in your formula. So if I wanted the width to always be five times the depth, I could just do D times five and press enter, and as long as I've got the correct syntax here, it will work, and it will run the calculation for me. And you can see that W is now five times D. So, we'll be looking at several examples of this in the next several movies, but this is where the formulas get input in a family environment.
Now, let's talk about trigonometry a little bit. We're going to do quite a bit of trigonometry because as I said, we can take our curves, and we can break those down into triangles. And once we have that triangle, we can calculate very precisely where each of the points needs to be. Well, sometimes it may be tough to remember exactly what all those trig functions are, you know, and we certainly have the little mnemonics that we learned in high school like soh-cah-toa and other tools that we can use to help us. I've compiled this cheat sheet right here, and this is actually reproduced with permission from a website called with called Revit Forum, and what you see here is a collection of triangles.
And essentially what it breaks down to is that you need to know two things about your triangle in order to calculate the rest. So, if you look here at the top, it talks about two sides. So, here's a diagram sides A, B, and C. And if you know any two of those sides, you can figure out the rest. You can figure out the angles, and you can figure out the third side. And so it tells you, if I know side A and I know side B, here and here, they're highlighted in bold, then these are the formulas you can use to calculate the rest of the triangle.
And then if you can continue down, if you happen to know one side and one angle, then there are similar diagrams that tell you what those formulas are. So these formulas are written in Revit syntax, so this is exactly the formula that you would write into that little field that we were just in, in the family editor. You just need to make sure you substitute the correct name for your parameter in that field there. So I'm calling it capital A right now. If your parameters called angle, then you would write out the word angle in the parenthesis and make sure that it is case sensitive.
So, that brings me to my last point and that is a few tips for using formulas. So, remember that you can use the various parameters within the family as the entries in the formula, so your parameters can be either variables or constants in that formula. So again, think back to the triangle formula we were just talking about, where it said co-sign A; well, A could be any parameter that's a valid angle parameter in your family, so again, no matter what you called it, you just plug that name in there. Formulas are case sensitive, so if you called it angle with a capital A, you have to make sure you that type it exactly like that in the formula.
Lower case angle will not be the same thing. Pay close attention to the units, I already briefly discussed that, but that's usually the most common place where you're going to run into errors in your formulas, and errors certainly be frustrating. And watch your parenthesis. Especially when you're making a detailed formula where you're nesting one formula inside of another formula. It's real easy to forget those parenthesis, and then that will cause the formula to fail, and usually the error message doesn't specifically say you missed a parenthesis. It says something a little bit more cryptic like that argument was unexpected, or this was unexpected, and so sometimes it takes a little bit of trial and error to try and figure out exactly what the error means.
So, we'll see several examples of formulas in the movies going forward, but I just wanted to take this opportunity to give you a quick introduction to that, if you've never really used formulas in family editor before. So make sure you check out those resources that I've provided, both the Revit help file, and the PDF that's included with the exercise files. And with that, let's go ahead and get started creating some content that uses formulas.
- Creating seed families
- Creating circles, ellipses, and arcs
- Controlling rotation
- Working with segmental and elliptical arches
- Using profile families
- Working with cyma curves
- Using fixed proportion and scaling