I have tried doing this for example

    bpy.ops.image.open(filepath="//../flags/6.png", directory="/Users/shak/Desktop/flags/", files=[{"name":"6.png", "name":"6.png"}], show_multiview=False)

But that didn't work.

My pathname should be correct and blender writes exactly this. But I can't seem to be able to put an image into a plane with code.

Does anyone know what can I do about it?

  • $\begingroup$ Does this answer your question? I can't load an image from a script $\endgroup$ Dec 31, 2022 at 13:40
  • $\begingroup$ Hello! Thank of the reply! I loaded the image into the blender. How do I then use it to change the plane image? I tried reload() and my code above, but it didn't seem to work. Console wrote bpy.data.images['1.png'], but I am not sure how do I then change the image of the plane. $\endgroup$ Dec 31, 2022 at 14:53

1 Answer 1


You want to assign an image to a plane, is that right?

Try this:

import bpy

image = bpy.data.images.load("C:\\Path_to_image\\images.jpg")

plane = bpy.context.object

plane.scale = (image.size[0]/100, image.size[1]/100, 1)

mat = bpy.data.materials.new("Material")
mat.use_nodes = True

tex_ = mat.node_tree.nodes.new(type='ShaderNodeTexImage')
tex_.image = image

principled_ = None
for node in mat.node_tree.nodes:
    if node.type == 'BSDF_PRINCIPLED':
        principled_ = node

if not principled_:
    principled_ = mat.node_tree.nodes.new(type='ShaderNodeBsdfPrincipled')

mat.node_tree.links.new(principled_.inputs[0], tex_.outputs[0])

output_node = mat.node_tree.nodes.new(type='ShaderNodeOutputMaterial')
mat.node_tree.links.new(output_node.inputs[0], principled_.outputs[0])


Let me know if this is what you want to achieve, the question wasn't very clear for me.


You must log in to answer this question.

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