2
$\begingroup$

I'm trying to automate a process where I have to change a Value node for all materials starting with the prefix mb:. I've been messing with it, but I'm such a novice with Python that I'm stuck.

Looking at the console, I see that the code for changing the value of the node would be this:

bpy.data.materials["mb:o:150:27"].node_tree.nodes["Value"].outputs[0].default_value = 10

But my issue is that I don't know how I would apply the variable of mb: to the to string in the above line.

Is there any way to do this?

$\endgroup$

1 Answer 1

3
$\begingroup$

You want to iterate over all materials and check each material's name. IF it starts with 'mb:' then modify it.

import bpy 
for material in bpy.data.materials:
    if material.name.startswith("mb:"):
        material.node_tree.nodes["Value"].outputs[0].default_value = 10

$\endgroup$
1
  • $\begingroup$ Thank you! I had a bit of trouble at first, but this solved it all. $\endgroup$
    – rioforce
    Feb 7, 2021 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .