8
$\begingroup$

I'm a seasoned programmer, but fairly new to blender and 3D-modeling in general. So to get an understanding of different properties I want to write python scripts to create multiple renderings with different settings of various values.

In the example below I have figured out how to change the Volume Absorption Density, ex:

bpy.data.materials['MyMaterial'].node_tree.nodes['Volume Absorption'].inputs['Density'].default_value = 100

But not the RGB-node. It seems I cant even get the current values out of it. Some things I have tried:

bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.r
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.outputs['Color']

How do I get and set output values of the RGB-node in py python-script?

enter image description here

$\endgroup$
12
$\begingroup$

Welcome to Blender.SE, UlfR.

Finding out a property in Blender is relatively easy. Make sure, you have python tooltips enabled (in the user preferences).

Then hover your mouse cursor over the property (in this case the color). A tooltip containing the python command will appear.

tooltip

The property you seek seems to be outputs[0].default_value.

def_rgb = bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value

It is a bpy_prop_array by default, so you may want to convert it to a list.

float_values = list(def_rgb)
$\endgroup$
  • $\begingroup$ Miceterminator beat me to it by 3 minutes. I will leave this answer up, as it mentions the python tooltip and his doesn't you could accept his answer as the correct one however. $\endgroup$ – Leander Feb 18 at 12:00
  • $\begingroup$ my problem was that bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value = (1.0,1.0,0.5,1.0) works but bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value produces nothing in the Python console. Converting it to list then displayed the hidden values. $\endgroup$ – rob Feb 18 at 12:07
  • 1
    $\begingroup$ You can also access the individual values directly from the bpy_prop_array via their indices, such as def_rgb[0]. $\endgroup$ – Leander Feb 18 at 22:21
8
$\begingroup$

As you already found you way to the node tree, the "Copy data path" option is generally very helpful:

Right click on the field you want to access and use the "Copy data path" option.

bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value

You can also look at the answers here and here

How to get data access to the data path

$\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.