### 1.5.3. Creating Data Trees

Example files that accompany this section: Download

##### Grasshopper contains tools for changing the structure of a data tree. Theese tools can help you access specific data within a tree, and change the way it is stored, ordered, and identified.

Let’s look at some data tree manipulations and visualize how they affect the tree.

#### 1.5.3.1. FLATTEN

Flattening removes all levels of a Data Tree, resulting in a single List. Using the Flatten component (Sets/Tree/Flatten) on the P output of our Divide Curve component, we can use the Param Viewer to visualize the new data structure.

In the Param Viewer, we can see that we now only have 1 branch containing a list of 48 points.

#### 1.5.3.2. GRAFT TREE

Grafting creates a new Branch for every Data Item. If we run the data through the Graft Tree component (Sets/Tree/Graft Tree), each division point now has its own individual branch, rather than sharing a branch with the other division points on the same curve.

In the Param Viewer, we can see that what was data with 8 branches of 6 items each, we now have 8 branches with 6 sub-branches containing 1 item each.

#### 1.5.3.3. SIMPLIFY TREE

Simplify removes overlapping Branches in a Data Tree. If we run the data through the Simplify Tree component (Sets/Tree/Simplify Tree), the first branch, containing no data, has been removed.

In the Param Viewer, we still have 8 branches of 6 items each, but the first branch has been removed.

#### 1.5.3.4. FLIP MATRIX

The Flip Matrix component (Sets/Tree/Flip Matrix) Swaps the “Rows” and “Columns” of a Data Tree with two Path Indices.

In the Param Viewer, we can see that what was data with 8 branches of 6 items each, we now have 6 branches with 8 items each.

The Flatten, Graft, and Simplify operations can be applied to the component input or output itself, rather than feeding the data through a separate component. Just right-click the desired input or output and select Flatten, Graft, or Simplify from the menu. The component will display an icon to indicate that the tree is being modified. Keep in mind Grasshopper’s program flow. If you flatten a component input, the data will be flattened before the component operation is performed. If you flatten a component output, the data will be flattened after the component performs its action.

- Flattened output P
- Grafted output P
- Simplified output P

#### 1.5.3.5. THE PATH MAPPER

The Path Mapper component (Sets/Tree/Path Mapper) allows you to perform lexical operations on data trees. Lexical operations are logical mappings between data paths and indices which are defined by textual (lexical) masks and patterns.

- The Path Mapper component
- Right-click the Path Mapper component and select a predefined mapping option from the menu, or open the mapping editor
- The Mapping Editor
- You can modify a data tree by re-mapping the path index and the desired branch

#### 1.5.3.6. WEAVING DEFINITION

Example files that accompany this section: Download

In this example, we will manipulate lists and data trees to weave lists of points, define a pattern, and create surface geometry.

- Revolved NURBS surface
- NURBS curve
- Curve array
- Division points
- Paths (indices) of points

- Array curves
- Dispatch curves into lists A and B, divide curves
- Cull points, weave, and revolve

You should now see an array of lines in the Rhino viewport. The three sliders allow you to change the length of the lines, their distance from each other, and the number of lines in the array.

- The Dispatch component sends every second curve in the array to a separate list.
- The Divide Curve component divides the curves into the number of segments specified by the slider. Adjust the slider to change the number of points.

- The cull patterns remove alternating points from each list.
- The Weave component collects data from the point lists according to a custom pattern. This data is fed into the interpolate component to create curves.