How to combine lists with common items?

I want to detect how many groups of elements are placed in a row. With the node GetSurroundingElements from SteamNodes I can get if an element is next to other. If I have four elements one next to other (ABCD), the node back me the collision with AB - ABC - BCD - CD. There is a function for combine all of them in an unique list? (Could exists more groups and groups with different sizes EFGH - IJKLMN…)

Thank you!



1 Like

Hi Sergio,

Try a combination of List.Join and List.UniqueItems.

Kind regards









Thanks for your help Vikram and David, and sorry because probably I did the worst explanation ever :slight_smile:

I’ll try again: I don’t want combine all the panels, I want combine them only if they are in the same row, so I need to get different lists which contains the different group panels



Hi Sergio,

So the Magic Node has to divide the elements into mutually exclusive groups based on the results of the GetSurroundingElements node?

Kind regards,





Are you looking to filter elements which are same in the list (Tools.GetSurroundingElements")


When I use “Tools.GetSurroundingElements” I get a lot of combinations. I want to reduce this combinations and generate a list for each group of objects.

Thanks for your help!

I’m now thoroughly confused :wink:

In one of your above posts you have included an image with two Watch nodes.

Consider we have a list with a similar structure comprising of only the Element IDs in that list.

What would the list (of Element IDs) that you want to obtain look like?



First of all, thanks for your pattience!

Sorry about my last five-years-old paint, I didn’t have a computer with Dynamo :slight_smile: With the next pictures I hope you can understand my question.

Thanks a lot!

Something like this?

Hi Vikram

I don’t think so. Looking at Sergio’s most recent post, where he shows the picture of tables, he wants to find the groups of tables. So far he has found each table’s neighbours using GetSurroundingElements. But he needs somehow to group the neighbours together.

Kind regards David

Hi Sergio,

I think this is quite a tricky problem, but interesting.

Here is a possibility using List.Reduce twice. It uses two Custom Nodes, but each of them is very simple. The only problem is keeping in mind how List.Reduce works.

You give List.Reduce a Function, a Seed and a List. It calls the Function once for each item in the List. At each call, the Function’s inputs are the current value of the seed and the item from the list; and it’s output is fed back in as the seed at the next call.

OuterGather’s List is your starting list, and it’s Seed/output is the exclusive list. In contrast, InnerGather’s List is the current state of the exclusive list, and it’s Seed is the current item from the starting list. InnerGather finds out if any items from the current exclusive list will match with the current item from the starting list, and so builds a new exclusive list that includes that item.

I had to use the Zebra package Logic.If in the InnerGather, since the built-in If node always Laces lists, and that wouldn’t have worked in this case.

Kind regards,


The Home workspace:

Custom Node OuterGather:

Custom Node InnerGather:

David, Studying your definition and still trying to wrap my head around it.

From my limited understanding of your approach, I think our basic assumptions vary :slight_smile:

Using the table analogy…

-You seem to have considered 9 different groupings of 9 table instances and arrived at reduced it to 3 groups of 9 table instances. No instance is repeated in another group.

-I’ve considered 8 groupings of 4 table types (some groups have multiple instances of the same type) and reduced it to 3 groups such that no group has duplicate types.

In other words, if each table type was of a different color, I’ve just ensured that every group has no two tables with the same color.

David, An alternate workflow starting with a list similar to your example and ending with a similar result…

File: CommonItems.dyn



Yes: I will in turn have to study your definition. I suspect there are several workable approaches.

I have made a test file (Revit 2015) with combinations of 1, 2, 3, and 4 desks, and a stub definition using GetSurroundingElements.

Kind regards





I’m quite ignorant when it comes to packages.

Which package does Tool.GetSurroundingElements belong to?

It’s from the Steam Nodes package.

You’ve both provided some really good examples of herding common sets together but how would you handle shuffled arrays that are out of order? It might be more efficient to use python script because then you’d be able to use the specialized “set” data structure:


Can always sort the list. :slight_smile:

File: CommonItems1.dyn



Sorry, I’m a little bit late with my response. First, David did the correct interpretation of the picture, there are 9 different elements. Second, David, Vikram and Dimitar I’m trying right now your codes. I also did my own code with Python and this is the result:

After many hours I got the desired result! I started to learn Python a week ago and it’s possible that my code made you cry, but anyway I going to share it:

Thanks for your help! Sergio