1
$\begingroup$

I'm trying to build an addon that makes it possible to batch render using Cycles directly from the UI. I've started from a script find a while ago here but I cannot find anymore to link for reference. Anyways, the script worked correctly but without UI so I've decided to port it into an addon that permits to make the same actions but when Blender is open.

Here the problem: my addon works. It correctly creates the panel, buttons etc, but when I click the render button Blender freezes and the only way to "recover" is by force-closing it. I've debugged the code line by line and find that the problem is when Blender calls the render.render operator (bpy.ops.render.render()), and that the same problem appears when you call the operator from Blender build-in Python terminal.

I know that the render.render operator is a C implementation and not a Python one, so maybe the problem resides in that, but the normal render button is implemented in the same way (it seems to me) and it works, and if in my addons I change the call to my operator render.batch with the call to render.render the behavior is normal (it renders the chosen camera), so I don't know what I'm doing wrong.

Below my new operator implementation, maybe someone knows how to help me.

class BatchRender(bpy.types.Operator):
"""Batch Render"""
bl_idname = "render.batch"
bl_label = "Subsequently render all selected cameras"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):

    sceneKey = bpy.data.scenes.keys()[0]
    r = 0

    for item in cameras:
        if item.custom.isSelected:
            bpy.data.scenes[sceneKey].camera = item
            bpy.data.scenes[sceneKey].render.filepath = "//" + item.name + str(r)
            bpy.ops.render.render(write_still=True)
            r += 1
        else:
            self.report({'INFO'}, "No camera selected for batch rendering")

    return {'FINISHED'}

Some more little clarifications:

  • cameras is a list of the cameras present into the scene
  • custom.isSelected is a camera properties implemented by me before into the addons, is a boolean property and work correctly (I've tested line by line the code as I've said before)
$\endgroup$
1
$\begingroup$

That is because Blender operators are modal: They block code execution until finished. The execute function is called in the same thread in which the GUI is drawn - So your Blender GUI freezes until the render is finished. A similar question with a solution can be found here: Is it possible to make a sequence of renders and give the user the option to cancel the process through the UI at any given time?

$\endgroup$

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.