SortByFunction not sorting properly

Here I am attempting to sort by Type. It doesn’t sort as it should

Not all object types are comparable. You would need to sort by the type name.
You may also need to use SortByKey instead of Function Apply since you’d be applying multiple functions.

Screenshot_2
Type name seams to be empty. How should I go about sorting this?

You’ll have to get the type from the instance and then the name from the type.

I found that element.name sortByFunction combo works in my case.
Now I got another sorting issue - since it’s sorting string it thinks 245 comes before 45. Can I get it to sort like it was a number?

That’s a bit more involved but it’s certainly doable. You’d have to split up the individual dimensions and sort them individually using “natural sorting”. There are a few packages that have nodes for natural sorting but I can’t remember which ones off the top of my head. There are other topics that cover this though, so you should be able to check them out and get an idea.

After saying all that, the alternative might be easier: convert the strings to numbers. You’ll still need to pull apart the dimensions but then you can convert them to numbers and sort them that way.

1 Like

Woah that is so useful. I don’t know which package adds this but the one I plugged in was able to sort it even without splitting up strings. Thanks very much!

1 Like