How to keep paths clean?

I am trying to take some branches out of a tree, modify them, and then put the tree back together. As I’m operating on the individual branches, I’ve noticed that some components will change the path of the input. For example, {4} will become {4;0}. This messes up the structure of the tree when I reassemble it. When I’m working with individual lists whose paths I care about this becomes a problem, because you can’t simplify a single list and flattening will also remove the useful information. Why do some components lengthen paths? Is there a way to avoid this, or do I always have to use Path Mapper to fix things before I put my tree back together?

tree problem.gh (13.0 KB)

you could use shift paths after your replace items components.

Thanks. Trim tree also seems to do the trick. I wasn’t expecting to be able to use these on a single branch, since simplify doesn’t do anything. I suppose I can parametrically control the shift length to catch however many zeroes get added, so this works perfectly!

Incidentally, does anyone know why these extra zeroes get added in the first place? They don’t seem to serve any purpose.

Edit: found the answer to my own question here.

The reason all these zeroes are added is because we value consistency over economics. It doesn’t matter whether a component actually outputs more than one list, if the component belongs to the 1:N, 1:N’, or N:N’ groups, it will always add an extra integer to all the paths, because some day in the future, when the inputs change, it may need that extra integer to keep its lists untangled. We feel it’s bad behaviour for the topology of a data tree to be subject to the topical values in that tree. Any component which relies on a specific topology will no longer work when that topology changes, and that should happen as seldom as possible.

1 Like

Hi, I have created a video tutorial where I explain why to avoid simplifying data trees and what is the alternative which includes how to safely clean your tree structure. You can check the video here: https://youtu.be/-DNYJAcoD5E