Given a data tree, it is sometimes congenial to change the data structure to do an operation, then return to the original data structure. I have been looking for a good way to do just that, and I think I have found a decent solution. However, I would like to hear any other suggestions as well.

In this example, I have 23 tree branches, each containing 6 list items (Point 3d). I want to flatten the tree, move the points around randomly, then return to the original tree structure.

My solution is to use *Tree Statistics* to get the paths of the original tree, then use *Replace Paths* to map the paths to the flattened data. There are two caveats that might not be plainly obvious:

- The original data and the flattened data need to be grafted. This is such that each item has its own tree path. This is because the
*tree statistics*essentially produces paths for each branch. - Tree statistics must all be provided for the flattened data(which is now grafted), because the
*Replace Paths*requires a search mask for which paths are to be replaced. In this case, I want to replace all the paths, so I just provide the paths for every branch.

In the end, a simplify operation resolves the grafting. You can see that I do this with the path mapper in this case.

Attached is my gh file.

Flatten (do some operation) Unflatten.gh (26.8 KB)