How to iterate through all materials and mute certain type of node?

I would like to find and mute (or unmute) all ‘Bevel’ and ‘AO’ nodes used in all materials.
What would be the best approach to make it quickly? Didn’t find anything useful among existing threads.

Well, what about using Python ? :stuck_out_tongue:

import bpy

# set to False to unmute
mute_state = True

for mat in bpy.data.materials:
    for node in mat.node_tree.nodes:
        if node.type in ["BEVEL", "AMBIENT_OCCLUSION"]:
            node.mute = mute_state
1 Like

I knew just a couple of loops will be needed, just didn’t know how to start :slight_smile:
Thank you for complete solution!

1 Like

Welcome :slight_smile:

In that case a good solution is :

  • Set one of the Blender windows as a console
  • Type bpy.data.
  • Hit CTRL + SPACE BAR for autocomplete.

Then it’s about logic …
You will see that, yes there is this materials in bpy.data
Screenshot%20from%202019-10-16%2012-29-25
Then type bpy.data.materials. and hit auto complete again :
Screenshot%20from%202019-10-16%2012-29-18
There are keys, and values, it looks like a collection, to be looped on.
Let’s have a look on the first element :
Try to do mat = bpy.data.materials[0] and you get the first material.
Then again, type mat. and again auto complete :
Screenshot%20from%202019-10-16%2012-35-06
etc … etc …


Basically, step by step, you will reach all the datas you want to modify.
And when you reach the step :
bpy.data.materials[0].node_tree.nodes[0].mute well, you understand the structure, and you are ready to set the loop ! :smiley:


See you :slight_smile: ++
Tricotou

2 Likes