Join Ian Siegel for an in-depth discussion in this video Creating a list of numbers, part of Dynamo 1.x Essential Training.
- [Instructor] Another powerful aspect of using Dynamo is the ability to process more than one piece of information at a time. In the next couple of videos, we'll look at a few examples of how list of numbers are created and how some nodes behave when they're fed a list of numbers rather than just a single input. First, let's begin with a very common node for creating lists of any kind called list create. We'll find list create in the core lists section of the node library.
Looking at this node, it appears to only have one input called item zero, but this node is unlike any node we've seen so far in that it has a plus and a minus button that let's us set the number of inputs that it takes. If I hit the plus button a couple of times, you could see it creates new inputs on the left hand side and if I hit the minus button, it removes them. Let's use this node to create a list of three numbers. Let's use three integer sliders as a way of creating our numbers. We'll find integer sliders under the core input section of the node library.
I'm going to click on the pull down menu to change the slider settings. Rather than having each sliders maximum value set to a 100, let's set it to 15 for this example. I'll collapse the slider settings and copy this integer slider two more times. To copy I'll hit Ctrl-C on my keyboard and then press Ctrl-V twice. Let's set the value of the first slider to say 5. Set the second slider to 10 and I'll leave the third one at one.
Let's finish up by plugging each of our three sliders into the three inputs of our list create node. Now let's preview the data coming out of the list create node. So far, we've only worked with a single item at a time, so we can expect to see a few differences now that we're working with a list. For starters, in the very first line of the preview, Dynamo tells us that the output is a list of data. Below that, we see three rows of information. It appears that we have two numbers in each row. First one inside a gray rectangle, and another number off to it's right.
You might recognize that the right half of each line are the numbers that we've plugged in as inputs. Five, 10, and one. In this case, we're working with a list of numbers, but we'll see examples in other videos of lists of other types of data too. So we've identified at the right side are pieces of data. What about the numbers in gray rectangles? When data is arranged in a list, each item will always come with a number and a gray rectangle called it's index. Remember that word, index, we're going to see that term quite a bit in future videos.
The index is kind of like the address or the identifier for each piece of data in a list. We'll cover the basis of list management in detail in another video but we'll usually see the index as a way of retrieving a specific piece of data from a list. You can use a node that points to a list and says I want the item at index one, which is the second item in the list. In this case, the number 10. Or I want the first item in a list, which is index zero. In every list you'll ever create or work with in Dynamo, the index of the first item will always be the number zero and the index of each item after that will increase by one all the way through the length of a list.
It probably doesn't feel natural for you to start counting with the number zero but this is very common in computer science. Just consider this a right of passage into the world of programming. From now on, you start counting at zero instead of one. It's also important to note that even though we're now seeing these extra numbers in gray rectangles listed in front of our data, Dynamo didn't change our data in any way. The index is just a way of numbering each item in a list. As far as we're concerned, this is just a list containing the numbers five, 10, and one.
One more thing to note about your new list before we move on, notice that the order in which we plug in our inputs is important. Dynamo assembles the items into a list in the exact order that we plug into the inputs. Dynamo doesn't automatically sort anything. If we wanted to change the order of the items in this list, we would need to either find a node that'll sort the list differently or we would need to change the order in which we plug in our integer sliders. So congratulations, give yourself a pat on the back because you've just created your first list in Dynamo.
- 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