Reorder elements in ascending order

Hi all.
I’m grouping and trying to sorting by ascending order a list of elements for be used in “Element.SetParameterByName”. But after to group the elements, just returns a bunch of the same element, I’m tried to use “List.SortGroupByKey” and “List.SortGroupByFunction”, no sucess.
Elements are separated into groups but not in ascending order.

Am I using the node wrong? Can you guys give me suggestions on how to get it working properly or other nodes I can try to accomplish my goal? any suggestion is greatly appreciated, Thanks!

Maybe use a Group by function node and an empty string node to the function input; Based on the screenshot, the elements are sorted by their ID.

Welcome. Try getting the names of the elements and sort that list first, then use that list as keys and create a dictionary using Springs nodes. I did something similar with assembly views. I had two groups of views. The names of the views in the second list were exactly the same as the views in the first list, but were out of order. I used the Springs.Dictionary.ByKeysValues to reorder the second list to match the first. Hope this helps!

Didn’t work

If you want to sort them then you need to use SortByKey. GroupByKey will only group them, not apply any sorting. You can combine the two nodes if you want them grouped and sorted.

Hi Staylor, I got this result. Did not work.

Since you have elements with the exact same name, you will need to use the List.UniqueItems node to weed out the duplicates and then use that list as the keys.

Could you give me an example? I tried using SortByKey, but did’nt work.

Message: “Warning: Internal error, report: dereferencing a non-pointer.
Internal error, report: dereferencing a non-pointer.
List SortByKey operation failed.
At least one object must implement IComparable.”

Your keys need to be comparable objects like strings or numbers. The type is still an element. You need to use the element Name like @staylor said.

An Element.Name node between the element Types and SortByKey should be all you need. Then you can group the elements with GroupByKey since they’re already sorted.

I can’t use List.UniqueItems because I need all the values ​​for autotagging.
Could you give me an example?

@luizg_mendes Maybe sort by key will do it?

The problem is that I can’t use strings and numbers in the “Element.SetParameterByName” node. So I must sort the elements in ascending order.

You don’t have to. It’s only so that you have something to sort/group the elements by.

2 Likes

Thanks Nick, Its worked!

Glad that worked, but I don’t think you need the Flatten node. SortByKey has two outputs so the preview shows both lists, but the individual outputs are just a single list (with sublists).

1 Like

Hi Nick
Your suggestion worked. But, in other project, when the mechanical equipment changes to FXSQ135PAVE capacity it ends up being considered as if it were FXSQ1PAVE, and goes to the top of the list, how could I fix that?
thank you for your attention

That’s just how Dynamo sorts by default. Search for “natural sorting” and you should find some suggestions. There should be a few custom nodes that will sort the way you want.

I took the Nominal Cooling Capacity information from a Type Parameter and filtered it out. Now it’s perfect. thanks!