This is how i could replace the Base Color if it was just a default color option : bpy.data.materials["Material"].node_tree.nodes["Principled BSDF"].inputs[0].default_value = (0, 0.1 ,0 , 1)

But I am wondering how i could do the same if I was replacing an Image Texture option instead.

Posting image of GUI for reference. (basically wanna simulate selecting an image in Python script)

enter image description here

enter image description here

  • $\begingroup$ if you just wanna exchange/replace (as your title says) "another" image you can use this: bpy.data.images['Feb-9_color.png'].filepath = ... new image.... $\endgroup$
    – Chris
    Commented Sep 3, 2022 at 6:13

1 Answer 1


Here is a complete setup for materials you can use. If you get stuck at any point please let me know. Hope it helps

import bpy

cube = bpy.ops.mesh.primitive_cube_add()
mat = bpy.data.materials.new(name='Material')
mat.use_nodes = True
bpy.context.object.active_material = mat

nodes = mat.node_tree.nodes
links = mat.node_tree.links

principle = nodes.new('ShaderNodeBsdfPrincipled')
principle.location = 200, 0

output = nodes.new('ShaderNodeOutputMaterial')
output.location = 600, 0

image = nodes.new('ShaderNodeTexImage')
image.location = -200, 0 
#Assign Image
image.image = bpy.data.images['YOUR IMAGE NAME HERE']

links.new(image.outputs[0], principle.inputs[0])

links.new(principle.outputs[0], output.inputs[0])

You must log in to answer this question.

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