# Change field of a node in a group

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.)

• Why you can't just use our nice script? – brockmann Jan 3 '18 at 14:49
• @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 – Ascalon Jan 3 '18 at 22:02
• It should also properly replace any group, otherwise let me know. – brockmann Jan 3 '18 at 22:11
• I don't want to replace the whole group, just change a value node within the group from 0 to 1. – Ascalon Jan 4 '18 at 0:06
• I don't care. Just thought, duplicating the group, changing the value and replace all the nodes takes 5 seconds to do... @Drudge – brockmann Jan 4 '18 at 18:13

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

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


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)