# How do I add nodes to all material that has "Leaves" in the name?

import bpy

#make shader for leaves
for material in bpy.data.materials:
if 'Leaves' in str(material):
nodes = material.node_tree.nodes

image1 = nodes.get(type= 'ShaderNodeTexImage')
princi = nodes.get(type= 'ShaderNodeBsdfPrincipled')
colRam = nodes.new(type='ColorRamp')

#Add different values for each object
princi.inputs[7].default_value = 0.1
hueSa1.inputs[3].default_value = 0.8
hueSa2.inputs[3].default_value = 0.9
mapran.inputs[3].default_value = 0.2
mapran.inputs[4].default_val


I'm trying to add nodes, link nodes to all materials that has "Leaves" in their name at the same time. It says the script has been executed but I don't see any changes to the materials.

If anyone could help me it would be great :)

• Please don't post screenshots of code. Instead, please cut and paste the code into your question. You can indicate that it is code by placing a line with three back-tick (accent-grave) () characters before it and another such line after it. Jun 10 at 16:46

You have several errors that should have shown up in your console window. Below is corrected code. Your errors

• Not precisely an error, but better practice is to use material.name rather than str(material).

• Your calls to nodes.get should have triggered error messages because they are formulating the arguments wrong. nodes.get takes a string, not a keyword argument.

• The correct spelling for creating a new color ramp uses type='ShaderNodeValToRGB' as its argument.

I did not verify that your links are going from the desired input to the desired output. Now that the code is modifying the materials you can verify this yourself.

Also, you chopped off the end of your code - the last statement you have is incomplete. If there were any errors after that, I couldn't have found them, of course.

# Corrected version
import bpy

#make shader for leaves
for material in bpy.data.materials:
if 'Leaves' in material.name:
nodes = material.node_tree.nodes

image1 = nodes.get('Image Texture')
princi = nodes.get('Principled BSDF')
output = nodes.get('Material Output')

$$$$