Material color randomizer

Here is the Revit and Dynamo files.

MATERIAL RANDOMIZATION.rvt (728 KB)
BUILDING FACADE COLOR RANDOMIZER.dyn (14.1 KB)

I don’t understand why you’re writing new code. The random color code will work as is, you just have to supply the elements in the correct order/structure and the materials to choose from.

I also don’t understand what your code is doing. Are you assigning the material then shuffling the elements around so there are no matching materials adjacent? That won’t work.

I did not re-write the python script. I am able to generate random colors for the selected elements no problem. Where I am running into issues is trying to make sure similar materials are not next to or above the same material.

Erik’s code is for a slightly more complex setup. I was assuming you’d use the one I posted above it.

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

It will work with colors or materials (should work with anything really) as long as the elements are sorted in rows. You may have some issues with the empty spaces (that might be your issue with your current code as well). You will have to fill the empty spaces with null values so that the elements line up correctly.

Still running into a roadblock.

The elements (I assume they’re panels) need to be grouped by row. Otherwise there is no structure to tell how they’re ordered.

The elements being selected are parts of a wall not individual panels.

But those selected elements are all individual parts right? They need to be grouped by location - one sublist per row.

So i am trying to get the x,y, and z coordinates to do the sublist, but dynamo does not seem to be extracting the points.

If they’re not point-based families or systems they won’t have a location point. You’ll probably have to look at the location curves.

So I was able to extract the surface geometry. How do you do a sub-list to have it sort?

You can use Surface.PointAtParameter to get the center point of the surfaces then sort them by location like you were originally attempting to do.

I was able to extract and sort the list by Point.X, but when i plug that information into the python script i am still getting an error. See snip below.

They need to be sorted and grouped. The python script has to know which row each part is in as well so it knows which parts are adjacent above and below. Each row should have its own sublist in the list of parts. This part is going to be tricky because your wall is not at 90 degrees.

Since I am not to savvy at Dynamo and am not sure how to continue I think I am going to abandon this project. Thanks for the help.

You’re so close. You have your parts sorted by X, but you need to first group them by Z.


I use Sort/GroupByKey but you can use Sort/GroupByFunction as well. Once they’re grouped by elevation you need to sort the sublists by X coordinate (using list levels).

I sorted by Z coordinates first then sorted my X coordinates. What I noticed is out of the 63 panels selected only 9 are showing up after the acquiring the Point.X coordinates. I think I got all the inputs correct, but when I run the script I still have the same colors next to each other.




I’m only showing part of my graph there. You’d have to figure out how it fits into what you already have. You’ll also need to sort and group the actual elements the same way otherwise you haven’t actually made any changes when you apply the materials.

Here’s everything working.


2 Likes

Just wanted to say thank you for all of the help. I was able to get the script to work, but still had some issues with some of the panels having the same color next to them. I assume there was something different when I translated the script from the example to project.

If you share your graph and code I can take a look at it.