Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 44

Tree Operations: Flatten, Graft, Simplify

Recommended resources

In our previous lesson, we established a solid foundation by learning to read and interpret the structure of a Grasshopper data tree. You now understand how data is organized into items, branches, and paths. This lesson takes the next crucial step: moving from passive understanding to active manipulation. Here, we will explore the three fundamental operations that allow you to reshape data trees to suit your specific design intent: Flatten, Graft, and Simplify.

Mastering these operations is the key to unlocking Grasshopper's true potential. They are the primary tools for controlling how different streams of data interact, enabling you to build everything from simple arrays to complex, responsive systems. By the end of this lesson, you will be able to apply these operations to restructure data trees, preparing them for the advanced modeling tasks ahead.

The Two Ways to Operate

Before we dive into each operation, it's important to know that Grasshopper provides two ways to apply them:

  1. Dedicated Components: You can find components for these operations under the Sets > Tree tab in the component palette (e.g., Flatten Tree, Graft Tree, Simplify Tree). This method is very explicit and makes your definition easy to read.
  2. Input/Output Menus: You can also right-click on any component's input or output parameter and select the operation from the context menu. This is a quick and efficient shortcut that embeds the operation directly into the data flow.
The right-click context menu on a component's input or output provides a quick way to apply Flatten, Graft, or Simplify operations without adding extra components to the canvas.

We will explore both methods. Now, let's examine each operation in detail.


Flatten: Collapsing the Hierarchy

The Flatten operation is the most straightforward. It removes all hierarchical information from a data tree, collapsing all items from all branches into a single, long list in a new branch with the path {0}.

Think of it as taking a complex system of nested folders and dumping all the files into one single folder. The order of the files is preserved (items from branch {0;0} come first, then {0;1}, etc.), but their original grouping is lost.

This is a "destructive" operation in the sense that you lose the tree's structure. Therefore, it should be used when you want to treat all items as a single, unified collection. A common use case is when you need to perform an operation on a set of geometry that is incorrectly separated into multiple branches. For example, lofting a series of profile curves requires them to be in the same list (i.e., the same branch).

The following video provides a clear, practical example of this.

Flatten - Graft - Simplify - Grasshopper Tutorial

This tutorial from the Rhino Grasshopper channel demonstrates a classic scenario where Flatten is necessary to perform a loft.

Watch the segment from this timestamp. The presenter has four rectangular curves, each in its own branch. Notice that the Loft component fails initially because it receives four separate branches with only one curve each. See how applying Flatten combines them into one branch with four curves, allowing the Loft to succeed.

To solidify the concept, let's look at a textual definition.

Lesson 3 - Data structures — Rhino Grasshopper Open Access ...

This chapter from a TU Delft textbook provides concise definitions for our three key operations.

In the section "Manipulating Data Trees," read the short paragraph under the heading Flatten Tree. It succinctly explains the function and gives a crucial warning about when to use it.


Graft: Building the Hierarchy

Graft is essentially the opposite of Flatten. Instead of removing structure, it adds structure. Specifically, Graft takes every single item in a data tree and places it into its own, new branch. This dramatically increases the tree's complexity and depth.

If Flatten is like emptying all folders into one, Graft is like taking a folder of 100 files and creating 100 new sub-folders, placing one file in each.

Why would you want to create such a complex structure? Graft is the key to creating "one-to-many" or "many-to-many" relationships between data sets. For example, if you want to draw a line from a single point (List A) to a list of ten other points (List B), you need to match one item with ten items. By grafting the single point, you turn it into a tree with one branch, which can then be matched with the ten-item list.

The next video demonstrates this concept exceptionally well, showing both what Graft does and, more importantly, why it is so powerful for data matching.

Graft, Flatten and Data Trees - Grasshopper Tutorial

This video from The Different Design provides an excellent walkthrough of the Graft operation.

Please watch the segment from this section on grafting. First, observe the simple effect of Graft: it takes a flat list of curves and puts each one on its own branch. Next, pay close attention to the Loft example. See how lofting a grafted list fails because each branch only contains one curve. This reinforces the idea that operations happen at the branch level. Finally, the most important part is the scaling example. The presenter wants to scale three groups of circles using three different scale factors (1, 2, and 3). Notice how simply plugging in the list of factors doesn't work as intended. By grafting the list of three numbers, its structure is made to match the structure of the circles' data tree, achieving the desired result. This is a core technique in parametric design.

Now, let's read the formal definition for Graft from the same TU Delft resource.

Lesson 3 - Data structures — Rhino Grasshopper Open Access ...

Let's continue with the TU Delft textbook.

In the same section, read the paragraph under the heading Graft. Compare this definition to the examples you just saw in the video.


Simplify: Cleaning the Hierarchy

The Simplify operation is a "housekeeping" tool. It doesn't change the fundamental grouping of items, but it cleans up the branch paths to their simplest possible representation.

As data passes through many components, paths can become unnecessarily complex. For example, a branch might end up with a path like {0;0;0;1}. If all branches in the tree share the common prefix {0;0;0}, this part is redundant. Simplifying the tree would remove this shared prefix, resulting in a cleaner path, {1}.

This makes the data tree much easier for you to read in a Panel or Param Viewer. More importantly, it makes it easier to match with other data trees that may not have the same complex path history. It is good practice to simplify data trees periodically in your definition, especially before you need to match them with other data streams.

Graft, Flatten and Data Trees - Grasshopper Tutorial

The same video also provides a concise explanation of Simplify.

Watch the short segment on simplifying from this timestamp. Note how the paths {0;0;0}, {0;0;1}, and {0;0;2} are cleaned up to become {0}, {1}, and {2}.

Finally, let's read the definition for Simplify to round out our understanding.

Lesson 3 - Data structures — Rhino Grasshopper Open Access ...

One final look at the TU Delft textbook.

Read the paragraph under the heading Simplify. This completes the trio of fundamental operations.


Visual Summary

The image below provides a perfect side-by-side comparison of these three operations applied to the same initial data tree. A curve has been divided into 24 points, which are organized into 7 branches. Observe the output of each operation:

  • Original Data (top right): 7 branches, paths from {0;0;0} to {0;0;6}.
  • Simplify: The structure is identical (7 branches), but the redundant {0;0} is removed from the paths, resulting in cleaner paths from {0} to {6}.
  • Flatten: All branch structure is removed, resulting in a single branch {0} containing all 168 points.
  • Graft: Each of the original 168 points is placed in its own unique branch, resulting in a tree with 168 branches.
A visual comparison of the output from Simplify, Flatten, and Graft components on an identical input data tree. Notice the changes in the number of branches and the path structure for each operation.

Conclusion

In this lesson, you've moved from being an observer of data trees to an active manipulator. You now have the essential toolkit for restructuring data in Grasshopper to achieve your desired outcomes.

Key Takeaways:

  • Flatten removes all branching, collapsing a data tree into a single list. Use it when you need to treat all items as one group.
  • Graft creates a new branch for every single item. Use it to create one-to-many relationships and control data matching.
  • Simplify cleans up the path notation of a data tree without changing its structure, which is crucial for readability and successful data matching.
  • These operations can be applied using either dedicated components or by right-clicking on the inputs/outputs of other components.

The concepts learned today, especially Grafting, are direct prerequisites for our next topic. We will investigate how Grasshopper components handle inputs with mismatched data structures, exploring the rules of Shortest List, Longest List, and Cross Reference. You will see how an understanding of Flatten and Graft gives you complete control over these powerful data matching behaviors.