Sort group ID to ascending row

Hello,
I have curves with named attribute group ID. In some cases are two splines in one group(it should stay like this). This is correct result of the previous tree.

0,1,2,3,3,4,5,6,7,9,9,11,11,13,14,15 as you see 8,10,12 missing

I want to shift the the IDs to ascending row with no gaps.

I can fix this with using points to curves, curve to mesh and sample nearest mesh island, then use this value as the new group ID.

0,1,2,3,3,4,5,6,7,8,8,9,9,10,11,12 now the row is ascending (desired result).

As still learning is there any more elegant/common approach?
THANKS!

Hello !
Hum , did you tried the accumulate field node ?
My 6th sense tells me that it might be possible to do something with it , however I’m not 100% sure how…
Post a .blend if you want someone to look at it !

have fun !

Hi Sozap, we share the same 6th sense, but no suitable solution on my side so far, was playing with the map range as well…

file to play:
sortID.blend (576.3 KB)

wondering if there is performance wise more elegant solution.

Thanks!
happy friday!:wink:

1 Like

Hello !

I tried something, not 100% sure if that’s what you want but it looks like so :


image

First we do sort elements based on group ID.
Then we do an accumulate field that increments 1 for each splines.
BUT, in fact it increments 1 only if current and previous curve’s groupID are different !

That’s another arcane of the mysterious but powerful accumulate field node !

That looks a bit faster, and maybe it’s a bit more reliable …

Have a fun !

4 Likes

And this is the reason I asked - I learned something new, BIG thanks!

1 Like

Ok great ! it was a fun exercise ! I’m glad it works for you !

1 Like

I tested this in real project and realized just one cosmetic thing, with the substract at the end you can get the -1 as start without you can lose the 0.
otherwise all works well and the technique is good!

1 Like

even more simple setup came to my mind, still as an excersise wondering this is possible without the sorting of the elements…