3
$\begingroup$

I'm trying to write a script that will tweak some settings in the compositor, then save the resulting image.

However, The resulting image is NOT receiving the changes that are being made in the compositor. I suspect that blender is not, "waiting for the compositor to finish" before saving the image.

I've tried using Application handlers, but I don't really understand how to use them in this case.

Any help? Here's the code in question, without attempting to use application handlers:

        #get the render result
        render = bpy.data.images["Render Result"]
        
        #set the value of a compositor node to 0
        bpy.data.scenes["Scene"].node_tree.nodes["color vs. depth"].inputs[0].default_value = 0
        #change the colorspace to filmic
        bpy.context.scene.view_settings.view_transform = 'Filmic'
        
        #save the image
        render.save_render(filepath = tool.my_path + tool.my_string + " COLOR.png")
$\endgroup$
1
  • 3
    $\begingroup$ it might be much easier to create a file output node in the compositor instead, this will anyways save the frame when you trigger a render $\endgroup$
    – aliasguru
    Commented Feb 21 at 7:23

1 Answer 1

5
$\begingroup$

You can check if the compositor is processing with bpy.app.is_job_running.

You do have to delay your script a little bit because the compositor process doesn't start until your script finishes. You can use bpy.app.timers.

import bpy

render = bpy.data.images["Render Result"]

bpy.data.scenes["Scene"].node_tree.nodes["color vs. depth"].inputs[0].default_value = 0
bpy.context.scene.view_settings.view_transform = 'Filmic'

def wait_for_compositing_and_save():
    if bpy.app.is_job_running("COMPOSITE"):
        return 0.01  # Try again in 0.01 seconds
    render.save_render(filepath = tool.my_path + tool.my_string + " COLOR.png")

bpy.app.timers.register(wait_for_compositing_and_save, first_interval=0.01)
$\endgroup$
1
  • $\begingroup$ This worked! Thank you so much! $\endgroup$
    – colorbomb
    Commented Feb 21 at 23:22

You must log in to answer this question.

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