how to link/reference the outputfilename to the .blend file name

Hi all,

does someone know how to create a variable in the output filename path in order to reference the filename of the blendfile?

for example: //output/exr/"$blendfilename_###"

so if my filename is “projectone.blend” my output file would be “projectone.exr”

I hope you understand what I mean :wink:

thanx for all your help in advance,
tencars

Sounds like a job for os.path.splitext()


import os
path_without_dotblend = os.path.splitext(blend_path_in)
path_with_exr = path_without_dotblend + '.exr'

import bpy
from os.path import splitext

if bpy.data.filepath:
    filename = bpy.path.basename(bpy.data.filepath)
    filename = splitext(filename) + ".exr"
    print(filename)
else:
    print("No filepath, unsaved blend?")

Thank you for the quick reply,

could I imput something like this directly in to the output field as an “expression” like in the screenshot (I know, it doesnot work like I did it ;(

thanks in advance,

tencars

There’s currently just “#” that acts as a placeholder for a number. I can’t remember for sure, but I believe there was a discussion once about what placeholders should be added. The most flexible approach would allow a python expression. Not sure how safe such an evaluation would be though.

You could try to use an app handler to set the output path before a frame is rendered, that might actually work well.

#bpy.app.handlers.render_pre.clear() # clear all app handlers if needed

def set_render_filepath(scene):

    # use any criteria and expression for dynamic render filepath here
    if scene.frame_current < 10:
        scene.render.filepath = "C:/tmp/below_ten_##"
    else:
        scene.render.filepath = "C:/tmp/ten_or_greater_##"
        
bpy.app.handlers.render_pre.append(set_render_filepath)

OK,

I have to admit I am a little lost here now,

I will have to look through that again :wink: