I’m trying to change a value in a node for all objects in the scene without success. I can change it for one material but can not for the life of me figure it out how to do it for all of them.
I can copy the full data path and set a default value for that one material
For all materials this is the closest I could get without getting any syntax errors but nothing is happening to the scene also.
Are you sure that the node type in question is called ‘OctaneUniversalMaterial’??
in the python console editor, you can type the following to see what the type value really is: print(D.materials['vray_Book61'].node_tree['Universal material'].type)
The node.type is normally not the same as the node.bl_idname.
When you create a node with: node_tree.nodes.new(type='OctaneUniversalMaterial'), that type parameter is actually the bl_idname…
So, in your loop, you should use this instead:
#[...]
#if node.type == 'OctaneUniversalMaterial':
if node.bl_idname == 'OctaneUniversalMaterial':
#.....
And just to be sure… Are you really using Octane materials? or are you just copy-pasting code from somewhere and hoping that will work?
Is there a way to change the “Power” value on the RBG image node specifically connected to the Normal socket?
Using my copy-paste abilities, I imagine I would have to refer to “RGB image.001”, but I’m not sure if I would have to link some information to the “Normal” socket or not.
If you have the reference to the OctaneUniversalMaterial, you could go backwards from the Normal socket to the node that’s connected to it…
# assuming the 'node' is the OctaneUniversalMaterial node
normal_node = node.inputs['Normal'].links[0].from_node
normal_node.inputs['Power'].default_value = 1.0
Can I keep the same structure in the upper part? How do I “connect” the two to make it make sense?
I tried the previous trick but of course it changed for all of them, not just for the one connected to the Normal socket. Not sure if/how I could use the node name “RGB image.001”. It’s the same in all materials
From what I could gather, “RGB Image” refers to the one connected to the Albedo and “RGB Image.001” is always referring to the Normal one in this case.
There are plenty of different ways to do that…
You can go from the ‘OctaneUniversalMaterial’ backwards to the node connected to it, or you can branch the for node in node_tree.nodes and change the node there…
Example of both methods:
for mat in bpy.data.materials:
if mat.node_tree:
for node in mat.node_tree.nodes:
if node.bl_idname == 'OctaneUniversalMaterial':
node.input[10].default_value = 1.0
node.input['Normal'].links[0].from_node.inputs['Power'].default_value = 1.0
for mat in bpy.data.materials:
if mat.node_tree:
for node in mat.node_tree.nodes:
if node.bl_idname == 'OctaneUniversalMaterial':
node.input[10].default_value = 1.0
elif node.name=='RGB image.001':
node.input['Power'].default_value = 1.0