Sorting, Grouping and Adding strings

Hello everyone,

Really hoping someone can help me with this.

In the image above I have combined a whole bunch of parameters which leaves me with many sub-lists of strings. What I am trying to achieve is to group each sub-list based on their SolarOrientation. For example I need to know how many walls in each sublist are facing “N”, how many are facing “E” etc. Then I need to add their area values together to give me one value for all of the walls that are facing a particular direction. The part that I am struggling with is keeping the list structure the same.
I cant seem to work out what to do, I have tried a number of approaches, most recently I tried using the List.GroupByKey node but quickly realized that I need to change the length of my list to use this.

Any direction or suggestion would be great.

Thanks very much.

Rather than concatenating the data into strings and then splitting it later, how about handling the separate pieces of data like this? As long as you are careful about the levels and use Keep List Structure judiciously you can GroupByKey and still retain the nested structure:

42555.dyn (22.9 KB)

Hope this helps,
Thomas

2 Likes

hi Mitchell,

I think you’re wanting something like this?

Best,

Ben

Hi Thomas,

Cant thank you enough, this is exactly what I am looking for. Really appreciate your time and detail!

Mitch.

1 Like

Hi Ben,

Thanks for your response, really appreciate it!
Thomas has given me information that helps keep my structure in place, which is imperative for me.

I really like your Code Block scripting though, that is very good to know.

Mitch

1 Like

Hi Thomas,

I wonder if you could help me extend this at all, or let me know if what I want to do is possible?

The way it is now works flawlessly, but I would like to extend its functionality to be able to group walls based on their orientation AS WELL as their function (Interior or Exterior). So have all the walls that are facing north AND are interior grouped together, and the walls facing north AND exterior grouped together. Is it possible to group items by more than one criteria like this?

Mitch

Hi @Mitchell,

You can do a further GroupByKey after the one for orientation to then have another level of nesting for the function groups. I’m a bit tied up at the minute but may get a chance to look later today

Thomas

Hi Mitchell,

It gets more complicated the further levels of grouping you add while maintaining the structure, but you can still achieve it with GroupByKey:

42555_FollowUp.dyn (34.4 KB)

At this stage, it might be easier and more maintainable to use a data structure like a dictionary to hold this information

Hope this helps,
Thomas

Again, thank you greatly for you guidance and time on this! I will give this a go shortly!
Unfortunately I have little knowledge of dictionaries and how they are implemented, but if that will make the handling of data better I will start to look into it.

Thanks again Thomas!