How to get the elements back by List.SortByKey?

Hi,

I have put a poly curve in my points and put it on a slope. Now I have sorted my ZAxis value. (from my polycurve) Now I want my elements that I have filtered to be linked to the same sort so that the difference of the slope can be calculated but the value of the elements is placed randomly.

How can I filter the value of the elements from top to bottom?

Maat x wijzigen.dyn (42.3 KB)

1 Like

I’m not sure I completely follow, but SortByKey sounds like what you want. It will let you sort the elements by z value.

1 Like

I typically use sort by function for point sorting. Keys work as well - a bit more advanced though.

2 Likes

@Nick_Boyts @GavC Thank you both!

My list is not numeric from 0 to 21 but the points are random. I would like to have them in order and then read out the parameters of the elements.

1 Like

Try to join the curve as polycurve (or polycurve by points if you have points first), then use springs nodes to get the points of the polycurve. In my experimentation it looks like the points fall in order when a polycurve is dissolved.

The problem is that I no longer have any curves. My foundation brackets are points.
I order him first the Y and the X. Then the Springs.PolyCurve.Points but I have lost my elements. My list of elements no longer matches the point list.

here a .gif to see what happens. Am I forgetting something?

Sort your elements with their respective points (SortByKey) or sort your points then check back to your original list for the initial index (should match the index of the element as well).

@Nick_Boyts
Thank you for you’re reply.

I’m fairly new with dynamo. Could you explain this?

SortByKey lets you sort a list based on another list of keys. In your case you want to sort the points based on their Y and X values. You can also sort their respective elements by those same Y and X values. This ensures that the elements get ordered in the same way as the points.

Thanks again, ive tried but its difficult for me.
Do someone have a example?

This should demonstrate the basic idea. I can sort (or group) the points by X value but I need to do the same thing to the elements to keep the same list order. You would sort and group by Y first. Then do another iteration for the X coordinates. The important part is that you’re applying the same sort/group logic to your points and your elements.

1 Like

Hi,

I have made this it is to sort first left-right and then top-bottom of elements based on it’s coordinates.

Why reverse the list? That would order them right to left. Edit: Unless you meant to do Y first. That would make sense.
And why flatten? That undoes the grouping that you just did.

this why
and yes i want to do Y first

You have to use list levels here because you have sublists. Flattening the list negates the grouping you did and will therefore ignore the sorting by Y as soon as you sort by X.

1 Like

you are right i can skip 3 nodes by setting levels.

1 Like

@Nick_Boyts @EzDoesIt Thank you both! Both are the solutions!