0
$\begingroup$

I am trying to make a script that will change the value of a specific node within a specific node group. I have seen from this question how to target a node within a material, but I can't see how to change a node within a group.

The target node group exists within several materials, but the materials vary in different scenes, so I don't want to have the script change a specific material unless it has to be that way.

(Note: I know a more common way to solve this would be to use a Driver and Custom Property to change the value of the node, and then have the script change the property. However, I'm running into some issues getting my custom properties to update their drivers reliably, so I'm exploring other options too.)

$\endgroup$
  • $\begingroup$ Why you can't just use our nice script? $\endgroup$ – brockmann Jan 3 '18 at 14:49
  • $\begingroup$ @brockmann I thought that was for replacing one node with another, not for changing the value of a node within a group? Will have to look again $\endgroup$ – Drudge Jan 3 '18 at 22:02
  • $\begingroup$ It should also properly replace any group, otherwise let me know. $\endgroup$ – brockmann Jan 3 '18 at 22:11
  • $\begingroup$ I don't want to replace the whole group, just change a value node within the group from 0 to 1. $\endgroup$ – Drudge Jan 4 '18 at 0:06
  • $\begingroup$ I don't care. Just thought, duplicating the group, changing the value and replace all the nodes takes 5 seconds to do... @Drudge $\endgroup$ – brockmann Jan 4 '18 at 18:13
1
$\begingroup$

You can directly access node group data from

node_group = bpy.data.node_groups['NodeGroup']

The node group name is the one chosen in the group node

Node group name in group node

Each node group then has it's own nodes -

node_group.nodes

You can find a node groups nodes from a material (don't confuse node name with node group name)

bpy.data.material['Material'].node_tree.nodes['Group'].node_tree.nodes

group node name

You can get the node group name from the materials group node in node_tree.name

for n in mat.node_tree.nodes:
    if n.type == 'GROUP':
        node_group_name = n.node_tree.name

See this answer for an example of creating a node group using python.

Once you have the group nodes you can access them the same as normal material nodes.

node_group.nodes['Diffuse BSDF'].inputs['Color'].default_value = (1.0,0.0,0.0,1.0)
$\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.