Say you have a datatree in Grasshopper. It has two levels of branches, and each branch of data has a number of items. We want to ‘flip’ the branches around, but leave the lists of data at the end of each branch intact.
As an example, let’s use the following structure:
And here’s what we want it to look like after:
As a param mapper, this action would look like this:
How would we perform this action using the C# code block?
private void RunScript(DataTree<object> x, object y, ref object A) { DataTree<object> rtnTree = new DataTree<object>(); for (int p = 0; p < x.BranchCount; p++) { int[] pathint = x.Path(p).Indices; GH_Path flippath = new GH_Path(new[] {pathint[1],pathint[0]}); foreach (var item in x.Branch(new[] {pathint[0],pathint[1]})) { rtnTree.Add(item, flippath); } } A = rtnTree;