Is there a more elegant way to renumber a path structure?

When dealing with a simple one level tree, the treesloth “Renumber paths” does a fine job, but I’d like to know if there is an elegant way to do it on, say, a tree with thwo branch levels :

I tried to do it with the path mapper, but I’m just too dumb, so I’ve managed to do it the hard way :


Smart path renumbering please.gh (13.1 KB)

Any more elegant suggestions ?

This could help you…


Smart path renumbering please 1.gh (15.9 KB)

1 Like

I tried it and inadvertently ended up doing the same but using a series to generate 0,0,1. Using the Index Map of Create Set instead was really smart!

I hope you don’t mind that I tied it up a little bit, there is a couple of futile ‘simplify’ and ‘flatten’ IMHO.

Using Text Join and Text Split to trick the situation…
Would use Group and Ungroup if it were about geometries…


Smart path renumbering please_re.gh (8.2 KB)

3 Likes

:rofl:

  private void RunScript(DataTree<object> tree, ref object output)
  {
    var outTree = new DataTree<object>();
    var lastHead = -1;
    var newHead = -1;
    for(var i = 0;i < tree.BranchCount;i++)
    {
      var path = tree.Path(i);
      var branchData = tree.Branch(i);

      if(lastHead == -1 || lastHead != path[0])
      {
        lastHead = path[0];
        ++newHead;
      }

      var newPath = new GH_Path(path);
      newPath[0] = newHead;
      outTree.AddRange(branchData, newPath);
    }

    output = outTree;
  }
2 Likes

This is very smart :

Thanks a lot ; quite more compact than my sprawling attempt.

Hmmm… This begs for a new “Pancake” component :wink:

By the way, was this achievable with the “Path mapper” ?
If not, I hope @DavidRutten will make this kind of path hearding easier in V2.

I understand that “any” tree can exist, and that it is very challenging to make a tool that can operate on such diversity of paths, but in the real world, most trees have a very simple structure, by design and by the nature of the data that is stored.
It would make sense to have tools that cater for these simple cases.

Hi Riccardo,

Indeed, this is a very straightforward way.
In fact, my data is originally Elefront Blocks.
I wonder if the “Group” and “Ungroup” components are native or come from a plugin… can’t remember.
One could also use Metahopper’s “Pack” and “Unpack”

By the way, how do you guys make that nice shaded box around the component names ?
Fancy box

Group and Ungroup are native gh components.

<kbd>Group</kbd> and <kbd>Ungroup</kbd> are native gh components.

Reminds me of a weird way to do this…

Of course… I just had to quote to figure the syntax out :man_facepalming:

Yeah I added it this morning after reading this discussion. At least I think what I added is what was discussed here.

2 Likes