# Split a list and operate on resulting groups

Hello,

I have the following case: I am getting a list of 12 lines based on a box which I want to sort based on length. Generally for these boxes I will have 3 set of equal length lines. I want to have the lines in each set extend by a certain value:

I am stuck here:

What would be the logic or the next steps in sorting and splitting the list of lines and then extending them in GH?
Thanks!

Not shure this is what you are looking for? (extend curve)

Thanks! What I meant is: how to extend the longest curves by 50, the medium length ones by 25, and the smallest by 10. I was trying to partition / split the list of curves based on their length and then somehow extend each resulting list… but evidently failing.

You can use “create set” and “member index”

extensionlines.gh (9.6 KB)

Here’s one method:

group_by_length_and_extend.gh (9.7 KB)

-Kevin

Both this and the next solution work beautifully -will have to break down the logic.
One unexpected thing I found is that they both break if I try to process two boxes at once -could there be an easy solution to that?

@kev.r

just flatten

Graft the list of boxes used as input. Post your own test geometry next time.

…wow?! I wish I knew exactly why things work in this case. Is there a way to visualize how an operator (in this case Extend Curve) combines lists, trees, data? For example if I wouldn’t flatten the input edge list, would there be something I could do with the data structure of the lengths to still ensure a good result?

Thanks -I will be more careful in the future.

You could do it now, in this thread. Because flattening data trees isn’t the only way, and often is not the best way.

Instead of grafting the ‘L0’ and ‘L1’ inputs to Extend Curve, you could graft the output of Merge. Or, instead of grafting the output of Merge you could replace it with Entwine.

This literally is my entire definition -a box and a couple of nodes.
temp_extend.gh (10.1 KB)

But you asked about multiple boxes - so where is that test geometry? People who ask questions should work as hard (or harder) to post code/geometry as the people who answer the questions.

Here without flattening.
extensionlines.gh (14.3 KB)

1 Like

Except that I see flatten used twice… but it works so who am I to quibble.

1 Like

I guess I couldn’t resist…

The easiest way would be to extend each line by a percentage of its length, perhaps rounded off with a step function between min and max…

that would be the easiest way, but it depends on what the purpose is of this line extension