# 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:** 5\
**Page:** 2

<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 3, 2018, 2:23pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/23 "2018-05-03T14:23:35Z")

</div>

It’s true that my code only works for orthogonal grids but I think you could get it to work with varying row lengths just by adding a try loop.

```
try:
     panelBelow = rowBelow[p]
except:
     panelBelow = None

```

I think the important part (in my solution at least) is maintaining a list of adjacent geometries and/or their colors. As long as you’re assigning values one panel at a time, you can always retrieve the adjacent panels and query their color. Any panel without a color (None) won’t hurt anything when comparing against your list of available colors.

---

<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:38pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/24 "2018-05-03T14:38:33Z")

</div>

I think the simplicity of your solution is quite nice! And must admit that the solution I suppose is quite a bit heavier.  
Though If panels are not organised by a continuous list of adjacent panels (grouped by rows) it will unfortunately not work, this is why I’m trying to utilize the geometry and find the intersecting panels and using this as the “sorting” criteria.

---

<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 3, 2018, 2:52pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/25 "2018-05-03T14:52:01Z")

</div>

> [@Jonathan.Olesen](#):
>
> this is why I’m trying to utilize the geometry and find the intersecting panels

This is definitely a more inclusive approach. Unfortunately it probably comes down to geometry intersection. However, with simple panel geometry it might not be a big deal. You could take your current panel and filter for all other intersecting (coincident) geometry. Take the assigned colors from the adjacent panels (again, None values are fine here, and expected) and compare them to your list of available colors. Now you have your list of allowable colors for the current panel and you just have to randomly select one.

---

<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:54pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/26 "2018-05-03T14:54:42Z")

</div>

That indeed is the plan, though I do not see it as a linear problem, as you are iterating over the bars:

for bar in bars  
if barcolor in adjacentbarcolor  
set barcolor random (Not same color)  
else  
pass

Though if I change the color of bar 1 based on the colors of bar 4 and 5 and I have to change the color of bar 4 caused by bar 7, then the color 1 is no longer valid. I might be over-complicating the issue. I simply find the problem quite interesting though challenging.

---

<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 3, 2018, 2:59pm UTC](https://forum.dynamobim.com/t/random-list-and-adjacent-families/21345/27 "2018-05-03T14:59:46Z")

</div>

Edit: Let me rephrase that for clarity.

You need to check all adjacent panels at once to avoid that problem. You can’t assign a color based on one adjacent panel then hope that you don’t run into issues later on. If you use the actual panel geometry or a single perimeter curve this should be straight forward. A single panel (in this example) can have up to 4 adjacent panels, however no more than 2 will ever have colors assigned as they’re being checked for the current panel.

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