2
$\begingroup$

I need to change the value of an RGB node programmatically. The data path of the node in question is bpy.data.node_groups["Compositing Nodetree"].nodes["RGB"], as can be seen in the screenshot attached.

Empty bpy.data.node_groups

However, if I enter that path into the Python console, no node groups are returned. I.e. bpy.data.node_groups.keys() is empty.

What is going on here? How can one access node groups?

$\endgroup$
3
$\begingroup$

You can access the compositing node tree via:

bpy.context.scene.node_tree

And your RGB node this way:

bpy.context.scene.node_tree.nodes['RGB']

As for why the tooltip shows a data path that you can't really access?
Don't really know, might be a bug.

| improve this answer | |
$\endgroup$
  • $\begingroup$ That did the trick, thank you! The data path displayed in blender is definitely wrong. $\endgroup$ – sebastian Oct 6 '15 at 15:46
1
$\begingroup$

I had the same issue with a different fix:

  1. I created the material with <MATERIAL> = bpy.data.materials.new
  2. Attached the material to the object with C.object.data.materials.append
  3. Set <MATERIAL>.use_nodes = True

And the path suggested by Blender to edit, e.g., specular intensity was misleading: It suggested bpy.data.node_groups["Shader Nodetree"].nodes["Principled BSDF"].inputs[5].default_value but node_groupswas an empty collection.

I could access the value in the node tree with the following path:

<MATERIAL>.node_tree.nodes['Principled BSDF'].inputs[5].default_value = 0

Hope this helps someone!
Cheers,
Andres

| improve this answer | |
$\endgroup$
  • $\begingroup$ Certainly helped me. I've successfully used: mat = bpy.data.materials.new(name='orange') mat.use_nodes = True mat.node_tree.nodes["Principled BSDF"].inputs[0].default_value = (1.0,0.5,0.0,1.0) $\endgroup$ – edna May 11 '19 at 4:10
  • $\begingroup$ Glad to hear that! the node system rocks $\endgroup$ – fr_andres May 11 '19 at 16:10

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.