I was wondering if there is some way to create a reverse “Entwine” function with native Grasshopper components. Context would be to take various DataTrees and merge them to one stream while conserving the tree structure, apply a common operation to them, then split the trees back in the original tree structure (and just reverse the effect of entwine).
Until now I have just written a custom component mimicing the behaviour of “explode tree” while conserving the “original” tree structure.
I think the idea would be to merge data streams and to split them apart again… Similar to Entwine/Explode but while maintaining the existing tree structure of the streams.
As long as your operation operates on single items at a time (i.e. no list
inputs) this works:
effectively, you temporarily discard the tree structure by entwining in “flatten” mode and then use unflatten to reconstitute each individual stream’s structure. Not the most elegant, and doesn’t work in every case, but it does work.
One last point – if you’re winding up with scenarios where a single tree has branches with different numbers of indices, (e.g. {0;3} and {0;0;4;6} in the same data structure) you’re probably not using trees as effectively as you could be. In a decade of Grasshoppering I’ve never once seen a legitimate reason to rely on structures like this.
Thanks, that looks promising
The random trees were just to test a rather general case and probably not a realistic scenario.