Video Script - Autodesk Design Academy

advertisement
Nested List Management – June 18, 2015
In this lesson we will explore concepts for how to manipulate lists and nested lists in Dynamo for Revit
and Dynamo Studio. Let’s begin by constructing a sequence of numbers to define the X and Y
coordinates of a “point-by-coordinates” node. I will use the search feature located in the node library to
add the “integer slider”, “number” node, and “point-by-coordinate” node to the workspace. In the
number string I will use the string 0..#a..1 to create a sequence of values starting at 0 for a count of “a”
at an increment of 1. I will connect the “integer slider” to the “a” input port of the “number” node.
Let’s search for a “watch” node to see the result of changing the “integer slider”. I will connect the
“number” node to the “watch” node. Once these have been connected I will connect run. Notice that
the list starts with an index of 0 and ends with an index of 49. The total number of items in our list
equals 50. Moving our “integer slider” we can see the changes occurring dynamically. Set the “integer
slider” to a value of 10 and turn on the background 3D preview. To navigate the background use ctrl+G
or the toggle in the bottom right corner of the viewport. Let’s connect the output of our “number” node
to the X input port of our “point-by-coordinates” node. The resulting sequence of points is flat or a
single continuous list. Each point in the list corresponds to an item index. To see this better let’s go
ahead and connect the output port of our “point-by-coordinates” node to our “watch” node.
Navigating our background 3D preview, let’s zoom in to gain a better view of our points. You can select
the points from within the watch node and see the index displayed dynamically in the background 3D
preview. Using the “list-get-item-at-index” I can retrieve a specific entity from a given list. Typing “getitem” into the search field returns “get-item-at-index”. I will supply the list of points to the list input and
an “integer slider” to define the index.
Notice that the index 50 is greater than the largest index in our list. I will modify the range of the slider
by clicking on the bottom right corner of the “integer slider” and modifying the maximum value.
Let’s create a polygon to more clearly view the isolated point. To do this we will first need to create a
“circle-by-center-point-and-radius”. Browsing to the node library we will click on Geometry-CircleCreate-By Center Point Radius. Using the output of “get-item-at-index” I will define the center point I
will use a “number slider”. Again, I will modify the minimum and maximum values making changes to
the “number slider” I will see changes to my circle update dynamically.
Going back into the Geometry category in our library, browse to “regular-polygon”. I will connect the
output circle to the input circle put on the “regular-polygon” node. I will use a “number” node to define
how many sides I would like to have in my polygon. In this case, I will use the number 4 to create a
diamond.
As I make changes to the slider identifying which item to pull from the list, you will see that the circle
and polygon are updating in the background 3D preview. If you would like to view either the circle or
the polygon right click on the corresponding node you wish to hide and turn off the preview.
To modify the structure of our list of points I will right click on the “points-by-coordinates” node and
change the lacing option to cross product. Remember that the current lacing option is indicated in the
bottom right corner of the node. The cross product show 3 X’s as an icon.
Now we will copy and paste the “integer slider” and “number” node to define a new sequence of values
for Y. In doing so you can see that our list of points is now a grid. By changing the number of points
defining Y we can see that the background 3D preview will dynamically update.
The number of elements in our list can be computed by using the “list-count” node located at Core-ListAction. I will connect the output port of my “point-by-coordinates” node to the input port of my “listcount”. Using a watch node I will take a look at the result. Here I can see that 10 items exist within my
list, this correspond to the number that we defined here in our number sequence. Let’s again compare
this number to the output of our “points-by-coordinates” node. Clicking on plus or minus in the “watch”
node will collapse or open the list that it contains.
If you would like to see how many items are contained per nested list we will need to use the “list-map”
node. Typing map into the search field, we will see that under core there is List-Evaluate-List-map. Let’s
connect this node to the output of our “points-by-coordinate” node. The function input port specifies
which function to apply to the element in a given list. Let’s connect the “list-count” node and view the
result using a “watch-node”. Notice than Dynamo has thrown an error and by hovering over the balloon
we can see a message pop up. The warning indicates that that function input should not receive a list
count connected to another list, but rather you will need to add a new “list-count” to the workspace.
Connecting the output of the “list-count” to the function input, we can use a “watch” node to view the
result. Notice that the “list-map” is returning the list count for each of our nested lists.
Next, I would like to switch the rows and columns in our nested list of points. To do this, I will use the
transpose node. By connecting the output port of the “points-by-coordinates” node, to the input of the
transpose I will see that I have a new list of points where the columns and rows have been swapped. To
see the results of the “list-transpose” more clearly I will connect the output to my “transpose” node to
the input of my “get-item-at-index” node. We can now see that in the background 3D preview we have
switched from columns to rows.
Download