Sorting with List.GroupByKey

I am trying to sort a second list, using the unique keys from the first list but am having trouble with the “List.GroupByKey” node, is there a better way for me to do this or are there other nodes that i should be using? Any help would be greatly appreciated, Thanks

Could you explain a bit more what you are trying to achieve here? You are also providing an unequal number of keys (51) and values (53) which is causing the List.GroupByKey node to not work.

1 Like

I am trying to measure the distance between spaces within the same family.

The logic I am trying to accomplish right now is, if the value of the primary parameter equals the value in the comments parameter, dynamo will get the location of those 2 spaces then draw and measure a line, to return the distance between the 2.

I’ve managed to sort out 2 list, is there a way to compare and format the 2 so that the lists are pointing to the right index on each other?

For example index 0 on the bottom list is “Department block - Marketing”, However “Department block - Marketing” is index 12 on the top list, can I make it so that they are either both the same index or compare the lists to ensure that the correct index is being retrieved?

I tried converting to string then using the “String.Contains” node but that doesn’t seem to work either

I’m still having difficulty understanding your end goal, but maybe this will help:


Group By Key.dyn (18.1 KB)

I’ve gotten closer but not quite there yet, how do I rearrange it so that the “==” node is all true, I have the lists that I want, but the index’s are not in the correct order, I have tried sorting the keys before the “List.GroupByKey” node but breaks the node.

I think it’s because you’re filtering your Comments groups but not your Primary groups. Your lists don’t match.

If the Primary and the Comments match then wouldn’t they be the same room and therefore be a point and not a line?

Thanks for all the responses, I got the script to work! it just required me to flatten and sort the 2 lists again using “List.SortByKey”

If you want both lists to be in the same order then just Sort first and then Group like you did in the second part. I don’t think there’s any reason to group the first time.

2 Likes

Hi @Nick_Boyts, I have another similar requirement. I want to Group hangers with “Total Strut Length” (1st grouping). Based on the total strut length grouping, I want to group hangers with “Rod Length 1” (2nd grouping). Based 2nd grouping, again I want to group hangers with “Rod Length 2” (3rd grouping). Once this list is sorted based on the above 3 groupings, I want to add “Support ID” values.
I tried the above approach but could not get the desired result. Please find below the image of the Hanger Schedule for reference. I hope my problem statement is clear.

Have you searched for similar questions across the forum? Sorting/grouping by multiple values gets covered pretty often. There’s no difference in how you handle more groups. It’s just list management.

Also, please show us what you’ve tried so far so we can give feedback.

Hi @Nick_Boyts, Ignore the above example which has 3 groupings. See below another situation that has 2 groupings requirements.
I want to Group structural framing with “Type Name” (1st grouping). Based on the type name grouping, I want to group hangers with “Element Length” (2nd grouping). Once this list is sorted based on the above 2 groupings, I want to add “Site ID” values.
I searched similar questions for sorting/grouping by multiple values. I tried to concatenate these two parameter values. See the below image of the schedule and Dynamo script. I have also attached the WIP Dynamo script.
I hope this helps.
Renumber Rack Elements by Parameter Values_WIP2.dyn (27.4 KB)


Concatenating values is one approach, but you’re not doing anything after that. All your dictionary nodes are missing inputs and you don’t really need a dictionary since you’re sorting and grouping with existing values.

Sorting and grouping with multiple parameters is just about list levels. Sort/group the elements by one value, get the second parameter value, sort/group by the second value within the previous groups.

If you want to stick with the concat method, sort by all the concatenated values, then group by the first value. You can then continue to add subgroups by grouping within the previous groups based on the other parameter values.

Hi @Nick_Boyts, Sorry I did not get time to troubleshoot last week.
Before concatenating, I tried the sorting and grouping method, which I find easier than concatenating. I am sticking to the sorting/grouping method. Please see the below image for the same. As you suggested I sorted and grouped based on two values, but when I tried to input grouped value into another grouping it was giving error. I tried different ways to input values in the second grouping but could not get the result. The Below image shows only sorting and grouping separately.


Renumber Rack Elements by Parameter Values_WIP1.dyn (31.3 KB)