1

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

Rick T
  • 4,391
  • 1
  • 20
  • 64
  • 1
    check out my answer here: https://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 ;) – Chris Jul 29 '21 at 06:17
  • @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? – Rick T Aug 25 '21 at 18:04
  • Can show us your tmp/tex_tures folder? – Chris Aug 25 '21 at 18:10

1 Answers1

0

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.

Chris
  • 59,454
  • 6
  • 30
  • 84
  • It is changed...I included the python code in the question above along with the blend file. here = bpy.path.abspath('/tmp/tex_tures') – Rick T Aug 25 '21 at 19:30
  • I downloaded your file and in the python code it wasn‘t changed…. – Chris Aug 25 '21 at 19:32
  • 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') – Rick T Aug 25 '21 at 19:35
  • The textures are in the ('/tmp/tex_tures') directory see image above with directory, are you saying they need to be placed else where? – Rick T Aug 25 '21 at 19:39
  • Ok, that they are in tmp I couldn’t see – Chris Aug 25 '21 at 20:04
  • What I've found out....I can get the script to create the files and directories with the line bpy.data.images[fileName].filepath = eachFile but it looks like Blender isn't sending / setting the new variables / with the new file names before any of the renders take place it gives an error if testing with a blank texture in the field so it looks like it's not setting the field to the new texture at all. GPUTexture: Blender Texture Not Loaded! not sure how to fix this though any thoughts? – Rick T Aug 26 '21 at 01:42
  • 1
    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 – Chris Aug 26 '21 at 06:05
  • thanks. I'll post another question to better define the issue and it may also just be a bug. I'll create a bug report in blender to see if it's a bug with the Linux version. Thanks again for your help. – Rick T Aug 26 '21 at 13:44