If the number data types are the "nouns" of a program, functions are the "verbs". This video will focus on the number data type, and will introduce simple mathematical functions that add two numbers together, round a decimal to the nearest integer, and test whether one number is greater than another.
- [Voiceover] Let's take a look at what kinds of things Dynamo can do when we combine Number Inputs with nodes that perform functions on numbers. Let's begin in the Operators section of the Node Library. Here you can see we have a series of mathematical Operators or functions like addition, we have subtraction, multiplication and division. We can test whether numbers are less than one another, equal to one another, or not equal to one another. Let's begin with something simple like addition. Going to click on the + node, which is going to drop an addition node onto our canvas.
This particular node takes an x and a y input, two inputs total. If we hover over the x input, you'll notice that Dynamo gives us a little bit of a preview, a description of the type of data that it expects in order for this node to run properly. Because it says var, it means Dynamo can actually take any variety of data into this node and it might perform slightly differently depending on what you give it, but we're not limited to only plugging in, say, a number data type. For this example, we'll plug in two numbers, x and y, to see how this addition node performs.
So I'm gonna navigate to the Core, Input portion of the Node Library, and drop in two Number data Inputs. I'll drop in two Number Inputs by clicking twice, and I'm also going to want to drop in a Watch node in order to see the data coming out of this addition node. We can find that under Core, View in the Node Library. I'm gonna go ahead and plug in both of my Number nodes into the the x and the y input of the addition node, and then plug the output into our Watch node.
So we've now built a function that is adding zero plus zero, and if you see what's returned in the Watch node, the answer is zero. So, congratulations, you've built your first Dynamo graph that is able to add two numbers together. Now let's see what happens when we change any one of our Number Inputs. I'm going to click inside the Number Input and I'm going to change it to, say, the number five. When I click off in space, you'll notice that our Watch node is now reporting the number five. Five plus zero equals five. Let's also change the Number plugged into our y input to say seven, and you'll notice that our Watch node updates the number 12.
We're not limited to typing in only whole numbers or only integers here. We could change the number seven to, say, 7.6, and you'll notice that our Watch node now reports the decimal addition as well. Five plus 7.6 equals 12.6. So, excellent, we've now built a program that takes two Number Inputs and adds them together. Now let's drop in a node from the Core, Math portion of the Node Library called Round, which will round the Number Input to the nearest whole number or the nearest integer. This is a great way to ensure that a node that requires an integer, actually gets an integer.
You'll notice that there are two Round nodes available. It's pretty common in the Node Library to find two nodes that perform the same function. The difference between those nodes is usually the inputs that they require. In this particular case, the first Round node only takes one input, a number, whereas the second one allows us to specify how many digits we'd like to round to. For this example, we'll use the first one. As you can see, the Round node only takes a single input, which is a number. Let's plug in our 7.6 Number Input into the Math.Round node.
Up until now, we've used the Watch node as a way of previewing what information is coming out of any given node. That can start to clutter up your graph, especially as you start to place more and more nodes in your program. There is another way that you're able to preview what information is coming out of a node. You can do it by hovering over the dark gray portion in the middle of a node. In this case, we're seeing the number eight. You'll notice that when you hover off in space, that preview collapses back into the node, but if you'd like to be able to continue to see it even after you've moved your cursor, you can hover over the dark gray portion, and click on the pin icon.
That will allow you to move your cursor and the node preview will remain visible. So as you can see, the Round node is taking 7.6 as the input, and it's rounding it up to the next whole number which is 8. If, for example, the number 7.6 was changed, say, 7.2, the Round node automatically updates its preview and it rounds 7.2 down to the nearest integer which is seven. You might have also noticed that as I was changing those Number Inputs, our addition output was also changing.
Now the power of Dynamo comes from the ability to string together multiple functions one after another. This Round node doesn't necessarily need to hook directly up to a Number Input node like this. We can instead hook it up to, say, the output of the sum node. I'm gonna go ahead and click on the output of the addition node, and I'm going to replace the input of the Round node. You'll notice that the wires adjust themselves because you're not allowed to have multiple wires that connect to a node's input. Only one wire can ever hook up to any given input. So what we've now accomplished is we've built a program that has two steps.
It takes two inputs, adds them together, and then rounds it to the nearest integer. Now we can always go back to the very beginning of our graph, change one of our inputs, and then watch the entire program recalculate live. If, for example, I were to change the number 7.2 to 9.8, Dynamo automatically runs those two steps. It adds the two inputs together, and rounds to the nearest integer, resulting in 15. Now let's take a look at the less than node, which is back in the Operator section of the Node Library.
Just like the addition node, this asks for two inputs. We can place two more Number nodes onto the canvas, but Dynamo allows the output of a node to be fed into the inputs of as many nodes as you'd like. So let's place the two Number nodes that we already have placed on our canvas into the inputs of our new less than node. Here you'll notice that the output of this node is a Boolean data type, or true or false. This node is asking the question, "Is x less than y?" In our case, the number five is plugged into x and the number 9.8 is plugged into y, so this node is asking, "Is five less than 9.8?" In this case, yes, five is less than 9.8, so it returns the value of true.
It's asking our data a question. We'll also notice that the order of these two inputs is very important. If we were to reverse them, we should see that the opposite is true. 9.8 is not less than five. We should see a false value. So after we've reversed those inputs, 9.8 is not less than five, so the node returns a value of false. So here's an example of a function that takes two Number Inputs, but it doesn't necessarily output another number. In this case, it outputs a different data type, a Boolean data type. Let's look at another example of that.
We're gonna focus more on geometry in later videos, but let's get a little taste of how those Number Inputs play into the way that we can start to build up geometry in Dynamo. Let's drop in a Point ByCoordinates node, which we'll find in the Geometry, Point portion of the Node Library. Once again, we're seeing that there are two Point ByCoordinates nodes which both perform the same function, but the difference here is that the first one only takes an x and a y input, whereas the second takes an x, a y, and a z.
Let's use the one that takes three inputs, x, y, and z. I'm going to click once to drop it onto the canvas. You'll notice that if we hover over any one of these inputs, Dynamo specifies that we do need to plug in a double, which is a number that's allowed to be a decimal, but Dynamo also tells us that if we don't give it any information, the default value is a zero. Currently, we don't have anything plugged in, so Dynamo's going to try to create a Point using zero as the x value, and the same is true for y and z if we hover over those as well.
You might have noticed that as soon as we drop this node on to the canvas, our background preview changed to display a new point that wasn't there a second ago at the origin of our Dynamo graph. Because we haven't plugged anything in, this point is located at zero, zero, zero, or the origin because Dynamo has set zero as the Default value for x, y, and z. I'm gonna go ahead and plug our five Number Input into the x input, and you'll notice that the background preview automatically adjusts. The location of that point is different now. Now it's at five, zero, zero.
The x value is five instead of the default value of zero. If we plug in our 9.8 into y, you'll notice that that point's location changes again. And of course, if we change the value of either one of these two Number Inputs, it'll recalculate the entire graph, including the location of that point. Now we've been doing an awful lot of retyping numbers in order to change the values of these Number Inputs, so let's drop in a Number Slider which is going to allow us to quickly and graphically adjust the Numbers value, just by clicking and dragging on a slider.
We'll find the Number Slider node in the Core, Input section of the Node Library, which we've already been to for our Number Inputs. I'm going to click on the Number Slider node to drop one into the canvas. So the Number Slider node looks a little bit different from the Number Inputs that we're used to seeing because there is a slider that we're able to click and drag to the left and right. As we drag to the right, you'll notice that the number output gets bigger, and if we drag to the left, it gets smaller again. By clicking on the pull down, we can adjust the settings of the Number Slider by clicking on the pull down button.
Here we can set the Minimum and the Maximum extents of the Number Slider. So maybe instead of going all the way up to 100, I'll set the Maximum to be 20. Now when I drag the slider all the way to the right, we can exceed that number. We stop at 20. Let's go ahead and plug this Number Slider into the z input of our Point ByCoordinates node. You'll notice that as soon as we plugged our Number Slider into the z input, the point moved up in space. The z value is now 20, but instead of retyping the number in order to change that z, we're able to use the slider as a way of quickly, dynamically, and visually updating the location of that point in space.
Now if we were to change our Step from point one to, say, the number one, we'll allow the slider only to return integer values. You'll notice that we no longer get decimals out of this Number Slider. In the same way, if we change this Step to two, the only numbers that will come out of the Number Slider are even numbers, or numbers that are divisible by two. So to recap, we began this example with nothing but two or three numbers, but by using nodes that perform different functions that take Number Inputs, we've been able to produce several different data types that quickly and dynamically update when the input numbers change.
- Placing and connecting Dynamo nodes
- Understanding Dynamo's data types
- Performing math functions
- Creating number lists and text strings
- Writing data to an Excel spreadsheet
- Creating points, curves, surfaces, and solids
- Analyzing geometry
- Linking a Dynamo-driven SAT into Revit
- Placing Revit families with Dynamo
- Creating Revit views and sheets with Dynamo