Change node input value for all materials

Hi folks,

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.

image
I can copy the full data path and set a default value for that one material

image
For all materials this is the closest I could get without getting any syntax errors but nothing is happening to the scene also.

Any pointers?

What does the system console tells you?

Also, your inputs[10] is the wrong variable… it should be node.inputs[10].default_value=1.0

It says “bpy.ops.text.run_script()”

But nothing actually happens.
Making the change you suggested gave me the same message and the same result.

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)

I’m copying from a material conversion addon but I’ll admit I have no clue what I’m doing. Never messed with code related things before.

image

Not sure I’m following your instructions the right way, but this is what I get.

Thanks for your interest by the way.

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?

2 Likes

It worked.
Thank you very much!

Both are truth…I was copy-pasting and hoping, trying to find some logic to what was happening, but I really am using octane materials.

There’s one more thing I need to change in bulk.


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

We have a name for that! we call it ‘Cargo Cult’. :slight_smile:

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

:joy: yeah…I’m not the first it seems…

I’m not sure how/where to incorporate this…
image
Can I keep the same structure in the upper part? How do I “connect” the two to make it make sense?

image
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
1 Like

That is some neat witchcraft…

I’m really grateful for your help in cleaning up this mess without having to go through each individual object.

Add two images here. Change ‘data-direction-horizontal’ to ‘data-direction-vertical’ for a vertical slider.


Have a great one.
Cheers!

1 Like