I have the multiple png images that I want to apply them to a predefined 3d object template. This can easily be done by choosing the option shown in the image attached and then select the .png file to import. How can I achieve this using python script? enter image description here

  • $\begingroup$ You want to load the image to the Image Texture node and connect the node to BSDF. $\endgroup$
    – Karan
    Commented Sep 30, 2022 at 19:26

1 Answer 1


The Image Texture node should be connected to the Principled BSDF.

enter image description here

import bpy

def apply_image(object, image):
    Apply image to the object.
    object (bpy.types.Object) - Object to apply image to.
    image (bpy.types.Image) - Image to apply to object.
    if object.material_slots:
        for slot in object.material_slots:
            if slot.material:
                node_tree = slot.material.node_tree

                for node in node_tree.nodes:
                    if node.type == 'BSDF_PRINCIPLED':
                        if node.inputs['Base Color'].is_linked:
                            image_node = node.inputs['Base Color'].links[0].from_node
                            image_node.image = image

apply_image(bpy.context.object, image=bpy.data.images['Test'])
  • $\begingroup$ It worked for one surface, Now how can I define the other surfaces and use this function to apply image to it? And another question is to create a script will open 3d template at start of Blender and then apply images and export(I want to run this processes in batches) $\endgroup$ Commented Oct 1, 2022 at 8:05
  • $\begingroup$ What do you mean by other surface? $\endgroup$
    – Karan
    Commented Oct 1, 2022 at 9:27
  • $\begingroup$ I got it. but now the main problem is to automate it for bulk images. I have so many images named 1.png, 2.png and so on. Is there anyway to open template file in blender, add images(using their different names), export it over 100 times? $\endgroup$ Commented Oct 1, 2022 at 12:32
  • $\begingroup$ DM me on discord Karan#5503 $\endgroup$
    – Karan
    Commented Oct 1, 2022 at 13:41

You must log in to answer this question.

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