I'm trying to run the following smallscript. The preview with 12 does render, but the last line of the script fails with this error:
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "D:\Programme\Blender\2.78\scripts\modules\bpy\ops.py", line 189, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Cannot render, no camera
But there is a camera
import bpy
def reset_scene():
for item in bpy.data.objects:
item.select = True
bpy.ops.object.delete()
for material in bpy.data.materials:
if not material.users:
bpy.data.materials.remove(material)
for texture in bpy.data.textures:
if not texture.users:
bpy.data.textures.remove(texture)
reset_scene()
bpy.ops.mesh.primitive_cube_add(location=(0,1,0))
bpy.ops.mesh.primitive_cube_add(location=(0,-0.05,0))
bpy.context.object.scale[1] = 0.1
bpy.context.object.scale[0] = 10
bpy.context.object.scale[2] = 10
bpy.ops.object.camera_add(location=(0, 4, 4), rotation=(-0.7853, 0, 0))
bpy.ops.object.lamp_add(type='SUN', location=(0, 5, 0))
bpy.data.scenes["Scene"].render.filepath = 'c:\test.jpg'
bpy.ops.render.render( write_still=True )
When I set the camera explicitly with this script:
bpy.context.scene.camera = bpy.data.objects['Camera']
it seems to work.
Why can't it find the camera automatically like when you press F12?