0
$\begingroup$

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:

node

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

something_wrong


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

animation_nodes_loop

$\endgroup$
  • $\begingroup$ May I ask why you are doing this? $\endgroup$ – Rick Riggs Mar 29 '16 at 3:22
  • $\begingroup$ sure.. I'm gonna create a room full of paintings hanged to a wall. $\endgroup$ – Francesco Yoshi Gobbo Mar 29 '16 at 3:25
  • 1
    $\begingroup$ 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? $\endgroup$ – Mentalist Mar 29 '16 at 6:44
  • $\begingroup$ 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.. $\endgroup$ – Francesco Yoshi Gobbo Mar 30 '16 at 6:29
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – Francesco Yoshi Gobbo Mar 30 '16 at 6:35
2
$\begingroup$

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
node_group = bpy.data.node_groups.new('NodeGroup', 'ShaderNodeTree')

# 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_group.outputs.new('NodeSocketShader','BSDF')

# create diffuse shader
node_diff = node_group.nodes.new('ShaderNodeBsdfDiffuse')
node_diff.location = (100,0)

# create links
node_group.links.new(group_inputs.outputs[0], node_diff.inputs[0])
node_group.links.new(node_diff.outputs[0], group_outputs.inputs[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 = m.node_tree.nodes.new('ShaderNodeOutputMaterial')
    outputNode.location = (300,0)

    # create node group and link to created group
    groupNode = m.node_tree.nodes.new('ShaderNodeGroup')
    groupNode.node_tree = node_group

    # create image node
    imageNode = m.node_tree.nodes.new('ShaderNodeTexImage')
    imageNode.location = (-300,0)
    # load image and set is as active
    imageNode.image = bpy.data.images.load(image_path.format(i))

    # link nodes
    m.node_tree.links.new(imageNode.outputs['Color'], groupNode.inputs['Color'])
    m.node_tree.links.new(groupNode.outputs['BSDF'], outputNode.inputs['Surface'])

This creates 244 materials, all linked up with a node group that you can edit (so you don't have to edit all 244). Remember to put in your full or relative file path in the image_path.

$\endgroup$
  • $\begingroup$ something went wrong at line 29.. what am I missing? added an image to the bottom of the question.. thanks in advice! $\endgroup$ – Francesco Yoshi Gobbo Mar 30 '16 at 6:25
  • $\begingroup$ Copying the script ino the console messes up identation. You can just copy it into the text editor and press Run script. $\endgroup$ – Parkuhr Mar 30 '16 at 13:13
  • $\begingroup$ I've already tried.. It return me "Python script fail, look in the console for now..." this is the reason why I tried by the console but I messed up identation probably ^^" I always try with a new file, nothing changes.. maybe could be easier something like: import images as planes, as coCoK said and so assign to these images the two group nodes and the image texture one You already build using the actual script? $\endgroup$ – Francesco Yoshi Gobbo Mar 31 '16 at 1:02

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.