In relation to this question: How to interrupt a rendering which is not displayed in the UI to interact with?
If it comes to stopping a batch render, I suggest you to not use the for loop, as it freezes the interface.
A nice way to do this is to use a modal. with timer event
So you create a list of the objects to render, at each modal cycle you will render.render on the object in the list[0], then you will use
to eliminate the object rendered with list.pop(0) and you will delete the object from the list, in the next cycle it will be examined if len (list)> 0 otherwise you will exit the modal.
in addition in the modal you can insert if event.type in {'RIGHTMOUSE', 'ESC'}:
This allows you to stop the modal loop, so it will stop your script, but it won't stop the last render it is running, but I'm sure what you are looking for is to stop the loop, so I think this answer could be useful.
This example replaces your loop loop, as the loop loop cannot be stopped, or at least it is an operation that I have never been able to do. So it will be all in the timer event, which will be ended when the list of objects to be rendered is empty.
In addition, this method will leave the interface free and will not block it, like the request to your question.
import bpy
class ModalExample(bpy.types.Operator):
"""Operator which runs its self from a timer"""
bl_idname = "object.modal_operator"
bl_label = "Modal Timer Operator"
_timer = None
list= None
def modal(self, context, event):
if event.type in {'RIGHTMOUSE', 'ESC'}:
#stop with Esc or Rightmouse
self.cancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
if len(self.list)>0: #if obj in list go to render
context.scene.render.filepath = '\\youpath'
bpy.ops.render.render(animation=False, write_still=True)
self.list.pop(0)
else:
#else stop
self.cancel(context)
return {'CANCELLED'}
return {'PASS_THROUGH'}
def execute(self, context):
self.list=[o for o in context.scene.objects] ##try to render by number of object in scene
self._timer = wm.event_timer_add(2, window=context.window)#You will be able to decide how many seconds the modal timer should run
wm = context.window_manager
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
wm = context.window_manager
wm.event_timer_remove(self._timer)
def register():
bpy.utils.register_class(ModalExample)
def unregister():
bpy.utils.unregister_class(ModalExample)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.modal_operator('INVOKE_DEFAULT')
So in this modal you can insert your script, which does what it has to do, in this example it is only the basis of a burst render.
bpy.ops.render.render()
? Would be helpful to see your actual code. $\endgroup$link
toFalse
to append the object, easy... I'm pretty sure that we can make it work better and there are a lot of things how we can improve your workflow. However, as already requested multiple times, we all need to know what you are doing in this case (limited by the operator). So what exactly is too crumbersome? How do you modify your objects? I suggest don't waste your (and our) time and tell us your 'holy secrets' in order to have a real conversation about the facts @ArthurBlaquart $\endgroup$