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!




3 Answers 3


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.

  • 1
    $\begingroup$ 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 $\endgroup$ Commented Feb 14, 2019 at 18:11
  • $\begingroup$ hex_ = 0xff884422; rgba_tuple = tuple((hex_//((256**(3-x)))%256) for x in range(4)) #for numerical hex $\endgroup$ Commented Feb 14, 2019 at 18:58
  • 2
    $\begingroup$ Inasmuch as it is item zero recommend using .inputs["Color"] $\endgroup$
    – batFINGER
    Commented Feb 15, 2019 at 7:59

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

  • $\begingroup$ 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? $\endgroup$
    – pezzatron
    Commented Feb 22, 2019 at 9:37
  • $\begingroup$ This is setting rgb values in hex format. $\endgroup$
    – JuhaW
    Commented Feb 23, 2019 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 maybe i'm wrong. In this solution you could write a hex to rgb conversion an output the rgb as in the screenshot.

enter image description here


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .