Sorting curves by Z value in GH

Hello everyone!
I am trying to sort a list of curves (for laser cutting) by height.
Every slice is 9.1m distant from the other, and I am trying to alternate them for putting one slice in group A, the next 9.1 upper slice in group B, and so on.
I tried to look for answers on the forum but didn’t find a way to resolve that without coding.
Can someone get a look to my script and maybe tell me their opinion please ?
SortingTopo.gh (444.4 KB)

Thank you, have a nice day

Vic

You can sort them by tree branch afterwards:

1 Like

First, avoid passing values through text panels. I use temporary text panels extensively while coding but they can be deleted easily without affecting results. Like this:


SortingTopo_2025Apr23a.gh (452.1 KB)

I don’t understand that part, or your GH code. So I compute an average Z value (purple group) and sort the curves by it. ColorJa colors the sorted contour curves; red for the lowest and hot pink for the highest.

The ‘Precision’ slider sets the distance between points; 1 is highest precision, 100 the lowest.

The ‘Z factor’ slider “magnifys” the elevation of each colored contour curve. Setting it to zero shows the original curve elevations.


SortingTopo_2025Apr23b.gh (452.6 KB)

P.S. If you like, you can group curves at the same elevation by branch, like this:


SortingTopo_2025Apr23c.gh (455.8 KB)

Hello,
first of all, thank you very much! It took me several hours to understand the logic behind the scripts but I think I learned a lot. I haven’t dived in the cluster yet but I wanted to say thanks.
I don’t know if I should close the subject as solved already but now I have a final goal, evaluate if a curve is closed, and if it is, move it in the next branch containing an open curve. That should fix my issue where little mountains on the topography appears in the wrong color! I think. Thank you I’m trying to solve it by myself but if you want to give me the cheat I promise to watch it only after many efforts ;p Thank you again for your time, have a nice day!

Starting with ‘SortingTopo_2025Apr23c.gh’, I added a quick hack to show the closed curves as surfaces (in red). There are five:


SortingTopo_2025Apr27a.gh (460.1 KB)

What makes you think they are in the wrong branch?

All five appear to be in branches with one unclosed contour curve. Instead of moving them as you suggest, it would be better to fix the code, eh?

Using the ‘Z factor’ slider in this view, the five closed contour surfaces are shown in white.

Data cleanup is often required in topo models like this. Especially in the bottom right.

P.S. Minimal code cleanup again but maybe better than nothing. :thinking:
Shaded instead of Rendered view.


SortingTopo_2025Apr27b.gh (476.9 KB)