Unflatten each branch of datatree?

Hi everybody,

I have an initial data tree that I want to unflatten. It contains 7600 items distributed across 2 branches ({N}).

What I want to do is unflatten this data tree using another data tree as a guide. The guide tree has 3800 items and follows this structure: {X;Y}.

In other words, I want to unflatten each branch of the first data tree using the entire second data tree as a guide.

The desired result should be a data tree structured as: {N;X;Y}.

Any suggestions on how to approach this?
UnflattenEachBranch.gh (151.8 KB)

in order to unflatten you need the same number of items on both trees

how were you planning to unflatten it using a reference tree that has half amount of items? like doubling the number of items per branch?

or you wanted to apply the reference data structure kind of separately to both your {0} and {1} branches?

if that is the case, this is the principle applied in a very NON-GRASSHOPPERY parametric way… like “manually built” just as a proof of concept

That is! In output {0;X;Y} branch will be the unflattened tree for {0} and in {1;X;Y} branch will be the one for {1}.

Am I making myself clear?

1 Like

That’s the point. However, in this example I have 2 branches, but that 2 is parametric in my script :frowning:

1 Like

it’s sort of easy to do parametrically with something like TreeSloth

image

UnflattenEachBranch_TreeSloth.gh (155.0 KB)

but a single gin tonic at lunch time led me to this, which I believe is a bit overcomplicated, and I don’t really know why it’s working lol

UnflattenEachBranch_gin_tonic.gh (161.0 KB)

the point is, given the fact that Unflatten will work on a single input that is always treated as if Flattened, then it’s the reference data tree that has to “be multiplied”

easy to do with Treesloth, you add (prepend) an index and you get a whole new branch duplicating the reference one… a bit more complex to do with standard components (but I also strongly believe there are far easier solutions I’m not aware of… I mean literally 3-components solutions that just do the job)


[edit] this maybe looks a bit less covoluted but follows the same process

UnflattenEachBranch_maybe_easier.gh (161.1 KB)

Yes! I think that’s perfect. Thanks!

I think I have found a new solution (I don’t know if I should call it easier) using Repeat data and Path mapper:


UnflattenEachBranch_maybe_even_easier.gh (152.1 KB)

2 Likes

it works well as long as your data structure is {A;B;C}, otherwise you’ll have to edit the Path Mapper :+1:

2 Likes