When I run bpy.ops.render.render(write_still=True) from Python on large files, Blender goes into "(Not responding)" mode and the CPU spins like crazy for a few minutes. During this time, most users are confused as to what is going on in the application.

When you render manually from the GUI, it shows progress updates and gives the user a generally comfortable feeling that stuff is going on under the hood.

Is there any way to render from Python without freezing up the UI?

  • $\begingroup$ You might be interested in this: blender.stackexchange.com/a/19431/28015. $\endgroup$ – JakeD Nov 15 '18 at 19:13
  • $\begingroup$ Thanks but I don't think that will help. My addon already makes heavy use of these, and they don't seem to be relevant to the problem. Am I missing something? $\endgroup$ – Chris Conlan Nov 15 '18 at 19:20
  • $\begingroup$ Modal operators do not lock up the Blender UI...AFAIK they are the only way of doing this from a Python add-on. $\endgroup$ – JakeD Nov 15 '18 at 22:42
  • $\begingroup$ Perhaps I should've been more clear. If you hit the F12 key, you will see an animation on screen of the scene rendering itself. If I could "hit the F12 key" from Blender Python, that would be great for me. Modal operators are for more lightweight continuous calculations than rendering. $\endgroup$ – Chris Conlan Nov 16 '18 at 15:53
  • $\begingroup$ You are right, but I don't think that there is a way to do that from Python quite so easily. You could start a different process to do the heavy calculations (and avoid the GIL) and use the multiprocessing library in Python to send updates back to the Blender UI by way of a lightweight modal operator. $\endgroup$ – JakeD Nov 17 '18 at 1:07

You can do this by passing the 'execution context'. By default the execute() function is run when calling an operator from a script. If you press the render button from within the UI the invoke() function is run. To do the same from a script you would pass 'INVOKE_DEFAULT' as execution context. So for example bpy.ops.render.render('INVOKE_DEFAULT', animation=False, write_still=True).

See also the Python API docs: https://docs.blender.org/api/blender_python_api_current/bpy.ops.html#execution-context

Or for 2.80 (which is basically the same at the time of writing): https://docs.blender.org/api/blender2.8/bpy.ops.html#execution-context

| improve this answer | |

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.