1
$\begingroup$

Rendering with a different texture filename using the texture node without manually changing the filename each time.

I have several different texture files that i want to render out using the same node group setup and blender file. is it possible to automate the renders but use a different texture filename in the texture node group? I know about doing a render from the terminal.

Example of rendering from the terminal below:

#Render animation in EEVEE from frame 0 to 100 from terminal in Linux
/snap/bin/blender -b /home/jp/Documents/My\ Documents/blender/texture_test.blend -E BLENDER_EEVEE -o /tmp/frame_eevee_##### -s 0 -e 100 -t 1 -a; espeak 'done with eevee render animation'

An example of what I'm trying to do is

  1. I have a node group in a blender file that has several image files that I want to render using the same node group and blender file. I have a list of files p1.png, p2.png, file_texture.png, block_text.png, etc... and each time it renders I want it to loop through and replace the texture image node filename and render the next file in the list. See red arrow where I want the filename to be replaced after each render is complete. Is this possible?

img1

Another example img2

Added Chris's python code and attached blend file:

import bpy
import glob
import os


print ("Script start")

scn = bpy.context.scene

# here = bpy.path.abspath('//Tex_tures')

here = bpy.path.abspath('/tmp/tex_tures')

output_path = scn.render.filepath

for eachFile in glob.glob(os.path.join(here, '*.png')):
    print(eachFile)
    fileName = bpy.path.basename(eachFile)
    print(fileName)
    fileNameStart = os.path.splitext(fileName)[0]
    print("start:", fileNameStart)
    
    #bpy.data.images['0063.png'].filepath = eachFile # change this to you texture name
     bpy.data.images[fileName].filepath = eachFile # change this to you texture name
    
    directory = os.path.join(here, fileNameStart)
    print("directory", directory)
    if not os.path.exists(directory):
        os.makedirs(directory)
    scn.render.filepath = os.path.join(directory,"")
    bpy.ops.render.render(animation=True)
    
    
bpy.context.area.ui_type = 'TEXT_EDITOR'

Upload tex_tures file locations:

textures_dir

Error it gives if Line 23 in the python code is added:

Script start
/tmp/tex_tures/2plantpic_test.png
2plantpic_test.png
start: 2plantpic_test
Traceback (most recent call last):
  File "/home/rt/Downloads/0-del for questions tmp/blender q/multi_render_tetures.blend/multi_render", line 23, in <module>
KeyError: 'bpy_prop_collection[key]: key "2plantpic_test.png" not found'
Error: Python script failed, check the message in the system console

$\endgroup$
3
  • 1
    $\begingroup$ check out my answer here: blender.stackexchange.com/a/218744/86978. Of course you have to adapt it to your needs, but i am pretty sure this is what you want. And it even (as a bonus) takes the name of your texture file ;) $\endgroup$
    – Chris
    Commented Jul 29, 2021 at 6:17
  • $\begingroup$ @Chris yes that's exactly what I'm looking for. The files are created with your script but it's using the same texture in the image texture node and it's not changing. I added your python code to the question any idea how to fix this? $\endgroup$
    – Rick T
    Commented Aug 25, 2021 at 18:04
  • $\begingroup$ Can show us your tmp/tex_tures folder? $\endgroup$
    – Chris
    Commented Aug 25, 2021 at 18:10

1 Answer 1

0
$\begingroup$

you need to change this line

here = bpy.path.abspath('/tmp/tex_tures')

to your folder, else it won't work.

Because the code searches for every png in that folder and then executes it.

$\endgroup$
8
  • $\begingroup$ It is changed...I included the python code in the question above along with the blend file. here = bpy.path.abspath('/tmp/tex_tures') $\endgroup$
    – Rick T
    Commented Aug 25, 2021 at 19:30
  • $\begingroup$ I downloaded your file and in the python code it wasn‘t changed…. $\endgroup$
    – Chris
    Commented Aug 25, 2021 at 19:32
  • $\begingroup$ Very strange I just downloaded the blend file again and that line is in there on line 12 that's where the textures are located. ('/tmp/tex_tures') $\endgroup$
    – Rick T
    Commented Aug 25, 2021 at 19:35
  • $\begingroup$ The textures are in the ('/tmp/tex_tures') directory see image above with directory, are you saying they need to be placed else where? $\endgroup$
    – Rick T
    Commented Aug 25, 2021 at 19:39
  • 1
    $\begingroup$ all i could do it try out my script on your blender version (if you tell me). My script worked for me as i wrote it (on my version) but i have to say i am working on macbook (maybe this makes a difference although it shouldn't) and i am not that deep in python/files with blender, so i am not sure whether i can help you $\endgroup$
    – Chris
    Commented Aug 26, 2021 at 6:05

You must log in to answer this question.

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