Need very small code for changing all material values at once

Hello,

I am looking for someone who can write small code for me.
I want to set all Specular and Metalic value to 0 in my scene. I have more than 100+ Materials and I can’t do it manually. So if anyone can help please reply here or can Email me on [email protected]

Thanks.

import bpy

# set this to False if you want to keep existing links and only edit values
remove_links = True

for material in filter(lambda m: m.node_tree, bpy.data.materials):

    tree = material.node_tree

    for node in filter(lambda n: n.rna_type.identifier == 'ShaderNodeBsdfPrincipled', tree.nodes):
        for name in ("Metallic", "Specular"):
            socket = node.inputs[name]
            if remove_links:
                links = list(socket.links)
                for link in links:
                    tree.links.remove(link)
            socket.default_value = 0
1 Like

Thanks for quick code. But is there any way if I want to set different value for metallic and specular?

import bpy

# set this to False if you want to keep existing links and only edit values
remove_links = True

new_values = (
    ("Metallic", 0.25),
    ("Specular", 0.15)
)

for material in filter(lambda m: m.node_tree, bpy.data.materials):

    tree = material.node_tree

    for node in filter(lambda n: n.rna_type.identifier == 'ShaderNodeBsdfPrincipled', tree.nodes):
        for name, value in new_values:
            socket = node.inputs[name]
            if remove_links:
                links = list(socket.links)
                for link in links:
                    tree.links.remove(link)
            socket.default_value = value
2 Likes

Thanks you very much

You’re welcome :slight_smile:

select all objects and press alt+click in the property you want to change, and it will change all the other objects properties at the same time, also you can use copy to selected option when right clicking the property as well…

1 Like