From the course: Learning Grasshopper

How to use data matching in Grasshopper

From the course: Learning Grasshopper

Start my 1-month free trial

How to use data matching in Grasshopper

- [instructor] Sometimes when working in a Grasshopper definition we'll want to combine components or parameters that contain lists of different lengths. Let's take a look at the example here on the left. I have a column of five points and on the right I have a column of eight points and a set of lines connecting the two columns. Those are controlled by these two point components, respectively and then this line component. If we think about it though there are many different ways to decide how the two groups of points are connected. And that's where the idea of data matching comes in. Data matching is handled by a set of components called "Longest List," "Shortest List" and "Cross Reference," these are located in the sets component tab in the list sub category. The default mode for data matching is called "Longest List" and that's what you see here in the example, elements from the shorter list must be matched multiple times to satisfy the longest list. So the number of connections should equal the length of the longest list. I can see here that the eight points on the right makeup eight connections, a few of which are repeated on the first element of the shortest list. Let's look at a few different options for how to customize data matching with longest list. In order to do that, we have to go beyond the default data matching, so we actually need to bring in a longest list component. Let's pull that up from the list subcategory and place that right here and I'm just going to splice it in to these two connections each one flowing out of my construct points components and flowing into my line component. So you can see nothing has changed yet but when we right click on this longest list component, we get a contextual menu that shows us some different data matching options. Repeat first, will repeat the first items in the shorter list. Repeat last as the default and that's what we saw at the beginning that repeats the last items in the shorter list. Interpolate tries to spread out the repetitions evenly over the shorter list. Wrap repeats the first items in the shorter list after matching last element and finally flip will count backwards from the end of the shorter list after matching the last elements. Okay, let's take a look at the shortest list data matching component. Let's get rid of that longest list and just place this in here. So this is where the shorter of the two lists take precedent and some elements of the longest list are skipped. So the number of connections should be equal to the length of the shortest list and I can see that's working for us here. So go ahead and right click on shortest list and look at the different options I have for how my data matching sets up. Trim start skips elements from the beginning of the longer list, so I can see that these first three are getting skipped. Trim ends skips elements from the end of the longer list, while interpolate tries to spread up the skip elements evenly over the course of the longer list. And we have one last data matching component called cross-reference. Let's bring that in and get rid of shortest list. Oops, cross-reference tries to make all possible connections between the two lists. So the number of connections should equal the length of the shorter list multiplied by the length of the longer list and in our case that's five times eight equals 40 total connections. And we can look at some options for how cross-reference matches by right clicking and bringing up the contextual menu. So I can see holistic is the default and that is where the most possible connections are made between each list. Diagonal, skips connections with the same numbered element in each list. So zero doesn't connect to zero, one doesn't connect to one and so on. Coincidence essentially does the same thing as diagonal but that's for data matching of more than two lists, which doesn't apply here. So we won't actually see a difference. Lower triangle only matches items from the first list with items from the second list where the index is less than or equal to it's own. So I can see this point is the fifth element in the shorter list. So all matching stops after the fifth element in the longer list. And we also have lower triangle strict which only matches items from the first list with items from the second list where the index is less than its own. Upper triangle only matches items from the first list with items in the second list where the index is greater than or equal to its own. And finally, lower triangle strict only matches items from the first list with items from the second list where the index is greater than its own. So those are the basics of data matching in Grasshopper. As we get into more advanced examples in other videos we'll see how this can become really crucial to controlling our data flow.

Contents