"No Image to Bake To" Error and accessing Blender properties

Hi,
I’m trying to write Lightmap generation script, but I’m stuck at “No Image to Bake To” Error and aborting execution of further code.

On official page is written that I have to use AO bake first, but I don’t know how to change the bake_type property by script.

When I manualy run the script two times, the second time it works, but I need to run Blender from external application with project file and script to be executed on it, so I don’t have chance to change the property or run script twice manually.

I’m also struggling with changing another properties like type of shadow and numerical values, enabling Ambient occlusion, Indirect lighting etc.

I don’t know how to access and change them. Those, which I finded in API are read-only and I can’t find set function or something like that.

I’m developing application with Windows UI(standalone application) which can through Blender create lighting in the input file, create lightmaps for every Mesh and save them to disk for further usage. Its bachelor thesis and I have to submit it soon.

So can somebody please help me with the script and explain how to access blender properties?

I’m using Blender 2.57b because of UV Lightmap pack, which I’m using in this script.

Script file
lightmapgenerator_v0.2.py

just like when you try to bake to an image when you aren’t using a script, the image must first exists!
add a


bpy.ops.image.new()

before you call bpy.ops.object.lightmap_generator()

Curious. Does the dimensions of the image have any bearings on the lightmap being generated? If so, wouldn’t you be better off using something like this?


fooImg = bpy.data.images.new( name="fooimage", width=400, height=400 )

To change bake type:

bpy.context.scene.bake_type = "FULL"

…enabling ambient occlusion, indirect lighting:

ls = bpy.data.worlds['World'].light_settings
ls.use_ambient_occlusion = True
ls.use_indirect_light = True

I don’t know, if I understand you completly, but if you mean UV coordinates for lightmap, they are generated by UV Lightmap Pack and so is the new image created by it.

I don’t know, if I understand you completly, but if you mean UV coordinates for lightmap, they are generated by UV Lightmap Pack and so is the new image created by it.

bpy.context.scene.bake_type = “FULL” isn’t working, I get AttributeError : ‘Scene’ object has no attribute ‘bake_type’

enabling AO, indirect lighting etc. is working, Thanks :slight_smile:

Problem with render baking is documented on official site on the bottom

http://wiki.blender.org/index.php/Doc:2.5/Manual/Render/Bake

they say that Win users have to do AO Bake first and then Full Bake. It have to solve the problem with “No image to bake to” error but I don’t know how to change the option by script…

Sorry, it’s:

bpy.context.scene.render.bake_type = "AO"

and…

bpy.context.scene.render.bake_type = "FULL"

i think you get : “No image to bake to” error because you don’t give any image ‘context’ before doing bpy.ops.object.lightmap_generator()

i tried your script and do not get that error if i do


bpy.ops.image.new(name="testbake", height=1024*2, width=1024*2)
bpy.ops.object.lightmap_generator()

Its bachelor thesis and I have to submit it soon.

i hope this script is only a very very small part of it.