For some reason i have append images , now i want load all image by step.

image_path  = C:
image_list= []
for fn in os.listdir(image_path):
    ###first_image = bpy.data.images.load(image_list[0])  <----?
    ###second_image =  bpy.data.images.load(image_list[1])   <----?

1 Answer 1


Try this to batch load a list of images in a folder:

import bpy
from os.path import join, isfile
from os import listdir

imageObjects = []
imagePath = '/users/you/yourImagePath'
imgFiles  = [
    join( imagePath, fn )                    # Create full paths to images
    for fn in listdir( imagePath )           # For each item in the image folder
    if isfile( join( imagePath, fn ) )       # If the item is indeed a file
    and fn.lower().endswith(('.png','.jpg')) # Which ends with an image suffix (can add more types here if needed)

# Load entire list of images
for imgFile in imgFiles:
    # Add to image object list to use later
    imageObjects.append( bpy.data.images.load( imgFile ) ) 

# Load a specific index from the list (5th in the list in this example)
imgObj = bpy.data.images.load( imgFiles[4] )
  • $\begingroup$ ty but i have to load not full image list because have some variable by controlling the loading , i have to know the way by load single image from list. for example the first image of the list and in the second step , load second image. $\endgroup$
    – Noob Cat
    Apr 2, 2019 at 8:48
  • 1
    $\begingroup$ @Andrea see edit and LMK if this is what you meant $\endgroup$
    – TLousky
    Apr 2, 2019 at 8:57
  • $\begingroup$ Sorry @TLousky in the first time i put name of node with diffuse = nodes.new(type='ShaderNodeTexImage') diffuse.location = (-600,550) diffuse.name = imgFiles[0] now name is all path of image.. in the first time is only image name. an idea? $\endgroup$
    – Noob Cat
    Apr 2, 2019 at 9:25
  • 1
    $\begingroup$ try to replace the imports from os.path and add basename. Like this: from os.path import join, isfile, basename. Then use it in the diffuse.name: diffuse.name = basename(imgFiles[0]). Basename extracts the filename from a full path. $\endgroup$
    – TLousky
    Apr 2, 2019 at 9:34
  • $\begingroup$ Work very fine is very usefull, ty $\endgroup$
    – Noob Cat
    Apr 2, 2019 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.