# Random.list and adjacent families

**URL:** <https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345>\
**Category:** Revit\
**Tags:** dynamo\
**Created:** [April 24, 2018, 7:51am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345 "2018-04-24T07:51:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![s163762](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@s163762](https://forum.dynamobim.com/u/s163762)\
**Post date:** [April 24, 2018, 7:51am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/1 "2018-04-24T07:51:56Z")

</div>

We have a curtain wall facade with smaller elements. We have 6 different families to fit into the elements. We have in dynamo made a randomizer for the different families but we would like not to have two of the same family next to each other (horizontal and vertical). How do we do that?

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [April 24, 2018, 7:57am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/2 "2018-04-24T07:57:10Z")

</div>

Please show is your work so far. 🙂 And maybe a quick graphic of what it is that your wish to achieve.

---

<div class="post-metadata">

**Author:** ![s163762](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@s163762](https://forum.dynamobim.com/u/s163762)\
**Post date:** [April 24, 2018, 8:24am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/3 "2018-04-24T08:24:35Z")

</div>

I’m a new user so it looks like i cannot upload anything

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [April 24, 2018, 8:28am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/4 "2018-04-24T08:28:31Z")

</div>

A dropbox-link or drive-link is quite fine 🙂

---

<div class="post-metadata">

**Author:** ![s163762](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@s163762](https://forum.dynamobim.com/u/s163762)\
**Post date:** [April 24, 2018, 8:34am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/5 "2018-04-24T08:34:50Z")

</div>

[https://drive.google.com/drive/folders/1aVzOKhoDfdLedW7Ru9HhdChJXR39K16x?usp=sharing](https://drive.google.com/drive/folders/1aVzOKhoDfdLedW7Ru9HhdChJXR39K16x?usp=sharing)

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [April 24, 2018, 9:05am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/6 "2018-04-24T09:05:03Z")

</div>

Is there any kind of logic to the placement of the panels prior to your randomization (in the order that they are loaded) so that you that way can distinguish the placement of the panels, as to not get the types next to each other?

Alternatively you can attempt to play with the boundingbox and intersect nodes to try and sort your panels of building 127 to not be next to each other. 🙂

Unfortunately I cannot do any testing as I would need the .rvt file with the families loaded 🙂

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 24, 2018, 9:19am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/7 "2018-04-24T09:19:50Z")

</div>

Iterating over each entire selection based off of the previously placed panel and the panel above or below it is an option.

Get all panel types,  
Remove the panel type which was placed to the left  
Remove the panel type which was placed below  
Randomly select one of the remaining panels. Move to the next cell and repeat.

Could be a fun one…

---

<div class="post-metadata">

**Author:** ![s163762](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@s163762](https://forum.dynamobim.com/u/s163762)\
**Post date:** [April 24, 2018, 9:26am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/8 "2018-04-24T09:26:01Z")

</div>

Now I’ve uploadet the revit file in “drev” 🙂

---

<div class="post-metadata">

**Author:** ![s163762](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@s163762](https://forum.dynamobim.com/u/s163762)\
**Post date:** [April 24, 2018, 9:26am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/9 "2018-04-24T09:26:55Z")

</div>

Can you elaborate on that? 🙂

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 24, 2018, 10:09am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/10 "2018-04-24T10:09:03Z")

</div>

Likely not today - to say it’s gonna be a long day would be an understatement. Perhaps tomorrow.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [April 24, 2018, 8:26pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/11 "2018-04-24T20:26:49Z")

</div>

This sounded fun so I tried it out. I kind of “brute forced” some things just to get it working so the code could probably be cleaned up and simplified but I think it does what you’re looking for.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/b/3b63bfe0cf9878a5b993f6e1c553635685d1522f.png)

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('DSCoreNodes')
from DSCore import *

dataEnteringNode = IN
panels = IN[0]
colors = IN[1]

panelColors = []
rowBelow = panels[0]

for row in panels:
	rowColors = []
	rowInt = []
	panelLeft = []
	p=0
	for panel in row:
		panelBelow = rowBelow[p]
		adjacent = [panelLeft,panelBelow]
		ints = [x for x in range(0,len(colors)) if x not in adjacent]
		rInt = int(Math.Round(Math.Random(-0.5,len(ints)-0.5)))
		i = ints[rInt]
		rowInt.append(i)
		rowColors.append(colors[i])
		panelLeft = i
		p=p+1
	panelColors.append(rowColors)
	rowBelow = rowInt

OUT = panelColors
```

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 24, 2018, 10:52pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/12 "2018-04-24T22:52:40Z")

</div>

That’s pretty much line for line how I would have done it. Good job @Nick_Boyts!

---

<div class="post-metadata">

**Author:** ![s163762](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@s163762](https://forum.dynamobim.com/u/s163762)\
**Post date:** [May 1, 2018, 8:20am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/13 "2018-05-01T08:20:22Z")

</div>

thanks!! 😃

---

<div class="post-metadata">

**Author:** ![s163762](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@s163762](https://forum.dynamobim.com/u/s163762)\
**Post date:** [May 1, 2018, 8:57am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/14 "2018-05-01T08:57:12Z")

</div>

We tried to upgrade the model with your help but we cannot figure out where the problem is. Should i change anything in the python script or just copy-paste it? 🙂  
i’ve uploadet the dyn file in google drive.

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [May 1, 2018, 10:49am UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/15 "2018-05-01T10:49:41Z")

</div>

This should work, though you should start out having the same amount of each “color” as I had to break up your lists to get it to work 🙂 This also means that some colors are in the wrong “place” as they are handled as a group of another color.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/b/1b00c057059223137b8acd956217bc7cf451a42b.png)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [May 1, 2018, 1:07pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/17 "2018-05-01T13:07:23Z")

</div>

Ah. I apologize. I didn’t know this was specifically a learning exercise. I usually don’t like to post full solutions anyway, but this felt like something fun to try out. I was expecting multiple solutions from the forum with the hopes of a discussion around the logic. My mistake.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 1, 2018, 2:00pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/19 "2018-05-01T14:00:29Z")

</div>

As a continued learning exercise, rewriting that code in design script would be interesting as we could ‘race’ the two… it’s a great way to learn the concepts and logic as well. 🙂

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [May 1, 2018, 2:03pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/20 "2018-05-01T14:03:24Z")

</div>

I was actually doing this when I was coming up with a solution… but I find Python just way easier when it comes to looping, so I gave up on the DS solution half way through. 😁

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [May 3, 2018, 2:15pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/21 "2018-05-03T14:15:34Z")

</div>

Hi @Nick_Boyts and @jacob.small

I think your solution works quite well for a single organized grid but when it comes to a randomly generated wall it might fall short.  
Using boundingbox and intersections I’ve captured the adjacent panels for each panel in the building in question. Though I might need the last push over the edge, so if you still think it might be fun please have a go 🙂

Below is how I see the problem:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/9/590f0bb5a3420a021a94f3e44909762e49d6dad0.png)

Currenlty I get my output as:  
{{4,7},{3,4,6,7},{4,6},{1,5,8},{0,1,2},{3,7},{1,2,8},{0,1,5},{3,6},{3,10},{5,9}}  
Where each list’s index corresponds to the panel and the content of the list is the adjacent panels.

Looking forward to see if you can tackle this one! 😉

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 3, 2018, 2:21pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/22 "2018-05-03T14:21:25Z")

</div>

My initial thought was less about finding the exact panels and more about generating the values - let the user worry about selection. As such, with my method the actual wall geometry is irrelevant. I’ll try and post some later which illustrates.

[Next page](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345.md?page=2)
