How to work with Grasshopper Data tree

6 rules how to work with grasshopper data tree

It is extremely easy to mess up the data tree structure in Grasshopper. Especially if a user doesn’t know what he or she is doing. Just chaotically grafting, flattening and simplifying to the point of accidentally achieving the desired result. Is not an optimal way of working. However, just sticking to some straightforward rules can result in fewer problems with tree structures. Here is my list of 6 good habits of how to deal with data tree structures in Grasshopper.

DATA TREE GRASSHOPPER

6 rules of how to work with tree structures in Grasshopper

1. Use panel and param viewer to check data tree structure

This one maybe will be obvious for many of you.

Of course, panel and param viewer will be helpful to check your data tree structure. Many transformations or modifications on the list expend “depth” of the path structure. 

What does it mean, and why is it like this? Look at example below.

Curve Divide: As an input, we give single items in the list: one curve and the division number.

DIVIDE CURVE Component
Divide Component - New data tree

In the curly bracket, you can see one zero in both lists (orange circle). When you hover over the points output of the Divide Curve component, you can see that the output will be represented in the list form ,,Points as a list”. Not every component does that. However, the Divide Curve is one of them. It means that Grasshopper will create a whole new list.

If we look at output data (red circle) will see two zeros in the curly bracket. The initial zero represents the original list and the second zero corresponds to the newly created path.

OK, You can say that this structure with many zeros is just unnecessary. It should be just one zero there. However, look at what happen if we change the input data from one item to three. 

First of all, we have a dashed wire from the output, which means that we are dealing with the data tree structure.
Second, we can see that the number of items from the original list jumped into the new path. So the first item corresponds to the first path, the second item to the second path, and so on.

Remember that we still have the initial zero before the new path number. These zeros are not unnecessarily garbaged as many people think. It tells a lot about the history of the tree structure, and working on complex data will be impossible without them.

Path in Data tree
Divide Component - Data creation

Conclusion is:

It is always wise to follow how the structure is changing upstream and be aware of all changes. Some of the component’s output will be presented in a more straightforward form. So it is crucial to be aware that some components make an additional patch and some do not.

One more thing. With Param Viewer, you can visualize how data tree structure looks like.

You can find it in Params–>Util and connect to this component your data tree. You can see how many branches and how many elements are in your data tree structure. When you double click, a visualization of the data tree will appear. When you work with a lot of data it is wiser to use a Param Viewer because you will get a good overview of how data is structured.

Learn Grasshopper

Sign up for free mailing and you will receive Grasshopper TIPS every week. 

 Join NOW – I’ll send the first secrets of Grasshopper right away!

2. Avoid simplifications and flatten data tree operations

Try to use as little as possible above mentioned

I know that in many cases, that is the easiest way of doing some operations. Simply flatten the whole tree, and everything will work properly. Right?

I have to admit that sometimes I overuse these operations just to get and see the result as soon as possible. And it looks natural because you are trimming `unnecessary` zeros in your data tree. However, afterwards, it is easy to forget about it, and that can cause a lot of trouble, especially when it comes to lists merging.

As I told you before, those extra “0”s are essential and can contain helpful information and prevent additional variability in your path.

Maybe in a simple script and just for one case is not a problem at all. If you exactly know what your inputs will be, not branching can be a solution as well. However, I suppose you are going to create clusters or programs that can solve many cases. Not just coping part of the script several times and do the same thing on a simple data. Grasshopper manages complex data pretty well, and input can be presented in the form of data trees. In that case, you have to avoid flattening and simplification and systematically make branching. 

Why?

Because when you are going to work with a more advanced data tree structure, these operations will destroy the whole system without any mercy.

Simplify and flatten data tree
Avoid Simplify and Flatten data tree operations

3. Use shift paths

All right, Kris. But what if I would like to create a script, and I am uncertain what input data will be? What should I do instead of flattening or simplification?

Try to use the Shift Path as much as possible.

This component allows us to restore previous information about data tree structure. Use these components whenever you need to go to your last data structure.

Shifting paths works like shifting lists; however, here we shift the indices in all data tree paths.

Offset to apply to each branch in the integer form. The offset value can be positive or negative, and negative numbers give results similar to the Trim Tree component. “Shift Path” by a negative value is like “Trim Tree” with a positive value. Still, I don’t know the reason why Grasshopper has two similar components.

Let’s go to an example:

Positive numbers approach the Data Tree differently. The component re-orders the data tree based on the smallest branch in a tree. For example: {0;0;0) and {0;3;0) (both structures end with a 0) with Offset 2 are combined into {0}.

The Shift Path option looks a bit like a controlled Flatten option. It allows you to move the data one or more branches lower or to collapse the data into a single branch similar to the Flatten option. However, now placed on a single branch.

Shift Patch and Trim in Grasshopper
Shift Patch with negative value work as a Trim tree with positive value

One more extra helpful component to work with Grasshopper Data Tree.

Based on a guide tree, you can unflatten a tree. This is useful if you need to change certain values based on a pattern that should continue no matter the branch an item is on.

So if you have to make some operations on a flattened data list, do it. However, use unflatten components with the guided tree structure afterwards. Flatten data tree, make operation what you need and restore tree with unflatten component.

In other words, we can say that unflattening a data tree is like moving items back into original branches.

Unflatten Data tree in Grasshopper
Example how to use Unflatten Data tree in Grasshopper

4. Use Data tree explode and patch mapper wisly

In one of my previous articles (LINK HERE), I recommended using Patch mapper as much as it is possible. However, at the end of the article , I presented flaws of this component.

Namely:

If any change in the source tree happens then, the component will stop working. Any simplification operation before the path mapper will block this component.

That’s why you have to be very precise in all changes and know how your data is structured.

The same happens with explode tree component. Every time a tree structure changes, the component will stop working and cause a lot of trouble.

So the recommendation is to design your scripts as though the upstream tree structure is not going to change. Use the shift paths component that I presented in the previous point. In this case, you will prevent your data from changing.

You can also program several rules in the path mapper component. However, I recommend keeping your patch in order, so using these two components will be no problem at all.

Do you know more components that are not recommended to use with changed data tree structure? 

Write in the comments below.

Learn Grasshopper

DOWNLOAD 5 STEPS TO LEARN GRASSHOPPER

5 Steps to learn Grasshopper is a guide full of books, exercises, tutorials and videos. Everyone will find something for themselves – regardless of the level of initiation.

Next tips for working with Grasshopper tree data

5. Don't mix data tree

All lists that will talk to each other should have the same number of items. This is a simple general rule that will help you to work with Grasshopper. There is just one case when it is not a problem while dealing with different numbers of items. When one of the lists consists of just one item. Then Grasshopper will automatically connect this one element with the rest (Based on the longest list matching). 

Nevertheless, I will anyway recommend transforming this list with one item into the list that will have the same number of elements. For that operation, you can use the longest list matching just to be aware of what you are doing. I recommend that for all beginners who are new to the data tree.  

That was about lists and items. However, this rule should be also applied to the branches. Again, the best is when you are working on data with the same structure. So in one data tree, you have the same number of branches as in the other one. You can obtain that by tree operation like graft, shift tree or path mapper. 

 

As with lists, this principle will also operate on tree structures when one tree has just one branch. However, this branch should be on branches with different numbers of items

Conclusion is:
Don’t mix the number of branches because You can find yourself at the point where there is no possibility of connecting some lists because items are in the different branches.

6. Check what you are merging.

Again general rule. 

Hold the path lengths of branches the same in your whole data structure. You can have a different number of items in each branch. And this is OK, and in many cases, it will be like that. But look closely into the branch index. The path lengths of branches should be the same. If you find one with a different number, something went wrong and needed to be fixed immediately. Primarily because of problems with merging together other lists.

Merging Data tree
Try to have data trees with the same depth

Do you have any questions?

What problems do you have while wroking with Grasshopper Data Tree?

Write an email at [email protected]

I always write back !!

Check out more tricks in Grasshopper

Grasshopper useful components

Grasshopper Data Tree – Path Mapper is a BADASS


If you want to get more information about Grasshopper and learn parametric modelling, download the free guide
 – FREE DOWNLOAD

Grasshopper is a plugin to Rhino that you can download HERE 

Did you like that post ? Share it with others !

We spend a lot of time and effort creating all of our articles and guides. It would be great if you could take a moment to share this post !

Share:

Comments:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Author:

Download BIM CASE STUDIES:

After reading this guide you will learn:

  • How BIM is used on the biggest projects in Norway
  • What were the challenges for the design team and how were they solved
  • What were the challenges on the construction site and what was our approach to them

Newest articles: