# How to control RGB color input via python script

As part of a wider script, I'm trying to build a script that will allow me to change the Hex value of an RGB node. I'm struggling though to find where to hook in to the hex value of the input node. Although not ideal, I could make do with changing the RGB value rather than the hex value, but I can't find where to get hold of this value either?

Any help is very much appreciated!

Cheers

Sam

Here is a guide to control cycles nodes with python.

So the code would look like this:

import bpy
mat = bpy.data.materials['Material_Name']
nodes = mat.node_tree.nodes
node = nodes.get("Diffuse BSDF")
# change the color
node.inputs[0].default_value = (0,1,0,1)  # green RGBA


This lets you change the value just one time and does not run in a loop like with animation nodes.

• hex_ = '00ff00' ;tuple(int((hex_+'ff')[i:i+2], 16) for i in (0, 2 ,4,6)) ###or hex_ = '00ff00ff' ;tuple(int((hex_)[i:i+2], 16) for i in (0, 2 ,4,6)) will return a rgba tuple – miceterminator Feb 14 '19 at 18:11
• hex_ = 0xff884422; rgba_tuple = tuple((hex_//((256**(3-x)))%256) for x in range(4)) #for numerical hex – miceterminator Feb 14 '19 at 18:58
• Inasmuch as it is item zero recommend using .inputs["Color"] – batFINGER Feb 15 '19 at 7:59

.default_value = (0x80/255, 0x80/255, 0x80/255)

• Thanks JuhaW - would you mind clarifying for me what the calculation here is doing? Am i right in thinking this is a method of changing RGB value to decimal value? – pezzatron Feb 22 '19 at 9:37
• This is setting rgb values in hex format. – JuhaW Feb 23 '19 at 11:21

One way would be to do it with Animation Nodes. I dint do it with hex directly because i think the color-in only accepts rgb, but maby im wrong. In this solution you could write a hex to rgb conversion an output the rgb as in the screenshot.