2
$\begingroup$

I have like 100 objects, each with its own material, different mesh, own texture and UV maps. I want to immediately adjust only one parameter for all the materials, say: metallic but I want to keep separate textures, so I won't just link materials. I found that "copy to selected" does not work for material properties (this would be a cool feature, by the way). I also watched a tutorial about group nodes and yeah, it's cool to control many materials with a single node, but I would sooner move 100 sliders manually, rather than set up a node tree for each material.

If there's no tool for it, I would be happy with a simple python script that takes all materials in the model and changes them one parameter.

$\endgroup$
1
2
$\begingroup$

You would have to iterate through all materials, get their node trees and find the principled bsdf to set its default values. Demo on how to change the Metallic value for all materials in the file:

import bpy

for mat in bpy.data.materials:
    if hasattr(mat.node_tree, "nodes"):
        for node in mat.node_tree.nodes:
            if node.type == 'BSDF_PRINCIPLED':
                for input in node.inputs:
                    if input.name == 'Metallic':
                        input.default_value = 0.7

If you'd like to change another property of the principled shader, here is a complete list:

Alpha, Anisotropic, Anisotropic Rotation, Base Color, Clearcoat Clearcoat, Normal, Clearcoat Roughness, Emission, Emission Strength, IOR, Metallic, Normal, Roughness, Sheen Sheen Tint Specular, Specular Tint, Subsurface, Subsurface Color, Subsurface Radius, Tangent, Transmission, Transmission, Roughness.

Note that some of them are actually vectors (yellow and purple socket) so you'd have to assign a tuple instead. Demo on how to set the Base Color:

import bpy

for mat in bpy.data.materials:
    if hasattr(mat.node_tree, "nodes"):
        for node in mat.node_tree.nodes:
            if node.type == 'BSDF_PRINCIPLED':
                for input in node.inputs:
                    if input.name == 'Base Color':
                        input.default_value = (1.0, 0.0, 0.0, 1.0)

Further reading: What is the meaning of the color of the node sockets in the node editor?

$\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.