Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This Blender function will go through a folder, pull all the jpg's inside, and map them to planes in Blender along the Z axis.
import bpy
import os
def imageLoad(imgpath):
files = os.listdir(imgpath)
#Get the names of the files in the provided folder
for x in range(len(files)):
imagename = files[x][0:20]
if files[x].endswith('.jpg'):
#Resize to fit the scene['Plane'].name = imagename
#Rename the plane to the 1st parameter
mat_name = imagename
mat =
#Create a material with that name[mat_name].use_nodes = True[mat_name]'ShaderNodeBsdfDiffuse')
inp =[mat_name].node_tree.nodes['Material Output'].inputs['Surface']
outp =[mat_name].node_tree.nodes['Diffuse BSDF'].outputs['BSDF'][mat_name],outp)
#Connect the diffuse node to the surface of your plane
new_img = = imgpath + files[x])
#Load the image from the file[mat_name]'ShaderNodeTexImage')
inp =[mat_name].node_tree.nodes['Diffuse BSDF'].inputs['Color']
outp =[mat_name].node_tree.nodes['Image Texture'].outputs['Color'][mat_name],outp)
#Connect that image texture node to the diffuse material[mat_name].node_tree.nodes["Image Texture"].image = new_img[imagename].active_material =[mat_name]
bpy.ops.object.select_all(action='DESELECT')[imagename].select = True
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_all(action= 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
#Use UV Smart Unwrap
imgpathfull = "C:\\Users\\Desktop\\"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.