Convert Colors from Autodesk.Revit.DB.Color to DS.core colorl

last thing I need to figure out for this graph lol but Im a python noob.
archilab wont accept an revit.db.color so I need to convert it before feeding it in.

AddFilterToTemplate.dyn (164.5 KB)

You can use the properties of the colour here to get their byte values (RGB), and then feed them into a colour by ARGB node in Dynamo to get a native colour.

Iā€™m not able to jump in Dynamo right now, but in Python it would look like this I think:

# Written outside Dynamo, so needs testing
import clr
clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *

# Get your list of DB colours
colorList = IN[0]

# Make lists to add to
r,g,b = [],[],[]

# Get their RGB values
for c in colorList:
	r.append(int(c.Red))
	g.append(int(c.Green))
	b.append(int(c.Blue))

# Send the output as three lists
OUT = r,g,b
1 Like

I keep getting an error, cant iterate over a non sequence, I think maybe bc I am using data shapes for the input and its running the dynamo script before the data arrives

Add more step, I just modify from @GavinCrump to resolve with input not is list

# Written outside Dynamo, so needs testing
import clr
clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *
def tolist(obj1):
	if hasattr(obj1,'__iter__') : return obj1
	else : return [obj1]
# Get your list of DB colours
colorList = tolist(IN[0])

# Make lists to add to
r,g,b = [],[],[]

# Get their RGB values
for c in colorList:
	r.append(int(c.Red))
	g.append(int(c.Green))
	b.append(int(c.Blue))

# Send the output as three lists
OUT = r,g,b

that works! thanks :slight_smile: I reeally need to level up my python skills

1 Like

@chuongmep If I understand, you instructed it not to run until tolist had a value so it would stop running before my datashapes input?

It just help you allway set input is list before use for to loop a list.

1 Like