How to Assign Items to Branches

Hello

Is there a native way component to assing items to branches using integers as a mask? Elefront’s “Create Tree” component somehow works but doesn’t respect initial hierarchy of branches.

This is what I came up with using C#. I am just curious if there’s a better easier way.

    DataTree<Curve> assignedItems = new DataTree<Curve>();
    for (int i = 0; i < I.BranchCount; i++) {

      GH_Path actualPath = new GH_Path(i);

      for (int j = 0; j < I.Branch(actualPath).Count; j++) {

        int p = M.Branch(i)[j];

        GH_Path newPath = new GH_Path(i, p);
        assignedItems.Add(I.Branch(i)[j], newPath);
      }
    }

    R = assignedItems;

Thanks

An example to play with:
AssignItemsToDatatreeByMask.gh (8.4 KB)

1 Like

Before I discovered the Elefront Create Tree component I usually used the Replace Paths component.

An example to play with would be nice

1 Like

I’ve added sample file to the post

1 Like

Hello,

Create Tree does the job as long as you provide him the complete path, not only the second level of the branch.

AssignItemsToDatatreeByMask.gh (17.4 KB)

1 Like

using @TomTom Fast Replace Path… if you could create the new paths inside the code would be interesting, but it seems to have a good performance.


AssignItemsToDatatreeByMask.gh (25.3 KB)

1 Like


hick.gh (15.7 KB)

2 Likes

Would love to see a native component similar to Elefront’s Create Tree component.

I’ve gotten Replace Path to work but it requires additional components to do what Create Tree does in a single component.

I’m hoping that this is worthy of a feature request.

1 Like