Can't get background rendering with a script to work

I want to render a scene in background mode with Blender 2.55 by using:


C:\Blender2.55\blender.exe -b C:	est.blend -P C:\render.py

render.py:


import bpy

scene = bpy.context.scene
scene.render.resolution_x = 800
scene.render.resolution_y = 600
bpy.ops.render.render()
img = bpy.data.images['Render Result']
img.save_render(filepath="C:\output.png")

I get an error message:


  File "C:\Blender2.55\2.55\scripts\modules\bpy\ops.py", line 162, in __call__
    ret = op_call(self.idname_py(), C_dict, kw)
SystemError: Operator bpy.ops.render.render.poll() failed, context is incorrect

This same code works perfectly inside Blender, so why does it do this when run in background mode?

Does it render in background without “-P C:\render.py”? Maybe it wants a frame number or an output path?

Yes, Blender runs normally if run without the script in background mode. The output is specified inside the script file, and no other parameters should be necessary on the command line to run the script.

Who else knows what is going on? Is Blender 2.55 not ready for a movie production library script yet???

Why shouldn’t they be necessary? They always where necessary. They are necessary. And they probably will be necessary in a year or so. Output may be as well specified in .blend file, but it will not render with or without the script.

A script like this worked in Blender 2.49b, where you can type
“C:\Blender2.55\blender.exe -b C: est.blend -P C:\render.py” and all the rendering and saving is handled by the script code. I’m just wondering what the right code to do this or whether Blender 2.55 is not fully functional in this respect yet.

So what are these magical phantasmal parameters that you’re so sure I need?

I solved the issue. DO NOT use old .blend or .blend1 files. Blender files that worked in 2.49b won’t be fully compatible with Blender 2.5+, especially when it comes to scripts. Make new .blend files or convert the old ones to 2.5 standard.

Nice to know, because I (often) use old *.blend in Bl 2.55 ;-).

Then you haven’t changed enough keyframe animation parameters yet in those scenes. They will break.