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!
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!
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.
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.
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).
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.