I would like to bake normals (and potentially other parameters later) of an object via python code.
I came up with the following code, but it fails on the last line saying that it cannot find a valid image to bake to (I use the standard blender scene with the default cube).
I suspect this is because the image I created is not linked with the UV Map generated from the cube_project function.
How do I associate it to the image ?
Or maybe I am taking a wrong approach?
import bpy cube = bpy.data.objects["Cube"] bpy.context.scene.objects.active = cube bpy.ops.object.editmode_toggle() bpy.ops.mesh.select_all(action='SELECT') bpy.ops.uv.cube_project() bpy.ops.object.editmode_toggle() image = bpy.data.images.new(name="test", width=512, height=512) bpy.ops.object.bake_image()