# How to import many images so assign to texture_node and duplicate “n” times objects and materials?

I am searching a way to:

• duplicate a selected object and It's material 244 times..
• import 244 photos (image_000, image_001, ...) in the scene
• assign these images to an image_texture node (included in the material previously duplicated)
• every material should have a name that follows the object's one: object.000 > material.000 ...

any way to do this? maybe by script.. I tried some but cannot find a way to duplicate last operation for more than one time

bpy.ops.object.duplicate()


My actual node setup is this:

I need to replace the actual image texture with another one that follows the same rule of images and materials: 000, 001, ... (or not.. I think this way It should be simpler and clear).

EDIT 01 in response to Parkuhr's answer:

something went wrong at line 29.. what am I missing? materials has successfully been created..is maybe because objects are missing? I started a new scene without objects/orphan data

EDIT 02 - ANIMATION NODES way

I currently figured out how to duplicate objects and it's materials by animation node

but not how to

• make an independent material for each of these objects
• linking the images to the texture node of every single material with the same end-name %0Nd

• May I ask why you are doing this? – Rick Riggs Mar 29 '16 at 3:22
• sure.. I'm gonna create a room full of paintings hanged to a wall. – Francesco Yoshi Gobbo Mar 29 '16 at 3:25
• Another approach you might consider is to make a picture object that uses a single massive texture that includes all the images. Then you can duplicate the object and change just the UV map to choose which image is shown. Or maybe use 4 such variations with a map of 61 paintings on each so as to avoid overloading Blender's Viewport (it tends to crash when textures are extremely large). Might keep farther away ones at lower resolutions as well. Would this be easier for you to manage than your current workflow? – Mentalist Mar 29 '16 at 6:44
• it is so much interesting! actually i found out a quicker workflow by animation nodes... I reached the 245 objects and 245 materials I was looking for.. unfortunately I still have found out a way to sequentially link the pictures, the research continues... or maybe I will finish in entering material by material and so selecting picture by picture, uhm.. – Francesco Yoshi Gobbo Mar 30 '16 at 6:29

You could use the import images as planes add-on from preferences->add-ons to quickly import your 244 photos as a plane with matching dimensions. The add-on lets you set basic material options for cycles and bi on import. The created planes and materials get the same name as the image. After import, you would just need to place the planes on the correct locations in your scene.

• not exactly what I was searching for but It works! :) I didn't try importing more than an image in a row by that plug-in! COOL! It just works! I keep the question alive because I'm searching a way to duplicate an existing object and it's materials (solved by animation nodes) and so to link a given picture to a given material's texture node with the same end-name of %0Nd ^^ anyway thanks for the cool reply! – Francesco Yoshi Gobbo Mar 30 '16 at 6:35

Here, have a script:

import bpy

# change these to fit your files
image_path = "img_{:03d}.png"
material_name = "mat_{:03d}"
num_images = 244

# create a group

# create group inputs
group_inputs = node_group.nodes.new('NodeGroupInput')
group_inputs.location = (-350,0)
node_group.inputs.new('NodeSocketColor','Color')

# create group outputs
group_outputs = node_group.nodes.new('NodeGroupOutput')
group_outputs.location = (300,0)

node_diff.location = (100,0)

for i in range(num_images):
# create new material
m = bpy.data.materials.new(material_name.format(i))
m.use_nodes = True
m.node_tree.nodes.clear()

# create material output
outputNode.location = (300,0)

# create node group and link to created group
groupNode.node_tree = node_group

# create image node
imageNode.location = (-300,0)
# load image and set is as active

• Copying the script ino the console messes up identation. You can just copy it into the text editor and press Run script. – Parkuhr Mar 30 '16 at 13:13