How to Apply Shift List Logic to Each Branch of a Data Tree?

Hello Grasshopper Community,

I’m encountering a data structure problem and would appreciate some guidance.

I have a data tree of points, and my goal is to create a separate polyline for each branch by connecting the points within that branch.

My logic for a single list of points is as follows:

  1. Take the list of points.
  2. Use Shift List to offset the list by one.
  3. Create Line segments between the original list (A) and the shifted list (B).
  4. Use Join Curves to connect these lines into a single polyline.

This logic works perfectly when I isolate a single branch from my main data tree (for example, by using Split Tree with a mask like {9;*}). It produces the exact polyline I expect for that branch.

However, when I apply the same logic to the entire data tree, it fails. The lines seem to be created incorrectly, possibly connecting points between different branches, and the final Join Curves result is not a clean set of polylines.

  1. Could someone please explain why this data matching fails when using the full tree? I suspect it has to do with how the Line component matches the two data trees (original and shifted).
  2. What is the correct way to structure this so that the operation is applied to each branch independently, achieving the successful result for all branches?

I’ve attached my GH file with the components in question. Any help or explanation would be greatly appreciated!

Thank you for your time.

0608_03_problem.gh (80.7 KB)

Maybe that’s too simple.
0608_03_problem a.gh (78.1 KB)

relative Item?

1 Like

0608_03_problem_jvs.gh (84.7 KB)

i forget to set “wrap Item”

2 Likes

shifting the LIST of paths gives you the next or previous no matter which position in the path is changed. but you want to change only the second.

Am I being daft, or won’t the Polylline component just do this for you without having to mess about with data structures?
(don’t mind the orange error - it’s because there’s a few empty branches)

1 Like

no it wont.
polyline connects the points in a list.
but a spiral like connecton to the next item in the next list is needed.
look at the original file. in the lower group is the same code as in the upper one but running on an isolated branch. that was done to show the desired result -but it does not work like that for all at ones

I was being daft :slight_smile: (which means this is an interesting problem!)

Ok, I think I have it. I ended up using a different trick to offset the lists by shifting each list an amount equal to its least-significant path index. I had to use Path Mapper to do the equivalent of Flip Matrix because Flip Matrix is far too picky about its inputs. If the incoming data structure changes (eg. there’s another set of these “trumpets” somewhere else, increasing the tree depth from 2 to 3) then the Path Map will also have to change to suit.

0608_03_solution.gh (58.5 KB)

(For clarity because I neglected to put values in Panels: The Clean Tree has all options set to True. The List Item has an index of -1)

EDIT: Sorry I didn’t realise that @Jakob_v_Schirmeister 's first reply was a complete solution. Even more elegant than mine :slight_smile:

1 Like

Yeah, this situation is pretty much what Relative Item(s) is made for.

1 Like

Hi Jakob,

Thank you so much for the incredibly clear and helpful response! My apologies for the late reply.

Your solutions worked perfectly and are exactly what I was looking for. The Relative Item component is a wonderfully direct approach that I wasn’t aware of.

Your explanation of why my original method failed and how to fix it by grafting the input to the Shift List was the real key for me. I now have a much better understanding of how to properly manage data trees to operate on each branch independently.

For context, I’m designing a space-frame style column for a project, and I thought I would have to process each branch manually. Your solution has saved me a tremendous amount of time and taught me a fundamental concept.

Thanks again for your help!

Hi Tom,

Wow, thank you so much for taking the time to build and share this alternative solution! Also sorry for unclear explanation of the spiral modeling. I really appreciate the effort you put into it.

Your approach using the Path Mapper is incredibly clever. I’m still learning the more advanced aspects of data tree manipulation, and seeing how you used it to create a custom “Flip Matrix” logic is a fantastic learning opportunity for me. Your point about its flexibility, but also the need to adapt it if the tree structure changes, is a very valuable insight.

And thank you for the humble edit at the end. It’s wonderful to see different ways to solve the same problem, and your method is a great example of advanced data management that I will definitely be studying from your file.

Thanks again for contributing your expertise!

1 Like