4
$\begingroup$

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

$\endgroup$
4
+25
$\begingroup$

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.

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

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

$\endgroup$
  • $\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 Feb 22 at 9:37
  • $\begingroup$ This is setting rgb values in hex format. $\endgroup$ – JuhaW Feb 23 at 11:21
0
$\begingroup$

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.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.