Unfortunately, this was not my aim. My aim was to override the graphics in view for each element of a specific type with a unique color. I think I am almost there, but I am a bit stuck on which direction to take.
Try to group your elements by type with a GroupByKey node where the keys input comes out of the Element.Type node (if needed, you will find indications about how to do that in this discussion, or try the search field)
As you can see the Structural Framing in the Structural Beam Systems only assigned a color to one beam. I will do some more testing.
edit: I ran my script several times and what I came across is the following;
colors are not uniqe to the types, because I generate random colors and assign them to the type it can occur that the same color is being used twice
I have no idea why some beams won’t change their color, it seems completely random. I added and removed some beams. Used structural framing or beam system, but I can’t seem to find a pattern.
edit: The only thing now is I don’t know how to store or save the unique colors, there are new colors created everytime the script is run. Anybody any idea?
edit #2: Is there also some way to prevent the projection lines from being overwritten by a color?
You’re using a Math.Random node to generate the list of colors. Since those colors will randomly be selected on each run, you’re going to get random results on each run.
To get a more consistent approach try making a range from 1-755, spacing the values by the total count of beam types. A code block like this should do:
1…765…#(List.Count(a))
Then Chop the list into three parts - one for the all red group, one for the all green group, and one for the all blue group.
Next use an if statement statement to convert the numbers into assignable color values (less than 256). Something like this in a code block will get you started:
A>510? A/3 : A>255? A/2 : A
You can now wire the numbers into the color creation node accordingly. After that your colors will change uniformly based on the number of types in your job. It won’t have any yellows//purples/cyan colors, but those can be added by working with a 1530 deep list.
You can also use some list manipulation to shuffle the nodes in a seemingly random -reproducible way. tricks (list.remove and list.getitematindex nodes with a mid range number, feeding those into a list.create, and repeat the process a half dozen times), but I don’t know that there is any real value to that.
Thanks for your reply, however I don’t understand this part.
Next use an if statement statement to convert the numbers into assignable color values (less than 256). Something like this in a code block will get you started:
A>510? A/3 : A>255? A/2 : A
I understand that I can’t exceed the RGB values, but how can I know with which integer to divide my values in the list?
I have no experience with Code Blocks. So I made the first part in Python.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
number_of_types = IN[0]
output = []
color_range = range(1,755, int(number_of_types))
def chunks(l,n):
for i in xrange(0, len(l), n):
yield l[i:i + n]
output.append(chunks(color_range, (len(color_range)/3) ))
#Assign your output to the OUT variable.
OUT = output