Change color of all the lights


Not sure if I put it in the right category but here goes:
I’ve got a short question regarding lights.

Can I change the color of all the lights using a python script and a hex code?

Thanks in advance,

— please remove this —

Yes you can do it.

If you are using blender’s internal engine - try this:

import bpy

color = '007F11'

r = float.fromhex(color[0:2])/255.0
g = float.fromhex(color[2:4])/255.0
b = float.fromhex(color[4:6])/255.0

for l in
    l.color = [r, g, b]

In cycles it’s a bit more complex but it also can be done.

Hi HeadHunter,

import bpy

context = bpy.context
scene = context.scene

def HexColorToRGB(colorstring):
    """ convert #RRGGBB to an (R, G, B) tuple """
    colorstring = colorstring.strip()
    if colorstring[0] == '#': colorstring = colorstring[1:]
    if len(colorstring) != 6:
        raise ValueError("input #%s is not in #RRGGBB format" % colorstring)
    r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:]
    r, g, b = [int(n, 16) / 255.0 for n in (r, g, b)]
    return (r, g, b)

lamps = [ for obj in scene.objects if obj.type == 'LAMP']

for lamp in lamps:
    lamp.color = HexColorToRGB("#AA1DEF")

PS. hehe … too slow. Ahah float.fromhex().

Thanks both, this will do!

EDIT: Hmm not entirely working Bartek.
When I enter 7FE1FF at color it does change, but according to the light settings it is changed to: BBF1FF
How did that happen?

The Hex value on the color wheel, notes that it is gamma corrected… which may have something to do with sRGB … Simple colors like FF0000 wont be affected.