# How to access bake margin from python?

I'm building a color ID baker and I'd like to access the margin slider on my addon. I've looked in the API and gone through numerous attempts, but I can't quite figure out the python command to change it, much less implement it elsewhere.

The bake settings are a collection of settings available in bpy.context.scene.render.bake.

So, to access the Margin you would do:

bpy.context.scene.render.bake.margin = 16


This was a little tricky to find, but there were a few hints.

1. Hovering over the Margin property showed the tooltip, which revealed that the bake options were going to be in the Scene's properties.
2. Baking is linked to rendering, which made me think to look under the bpy.context.scene.render settings.

The best way to explore the Api is via blender's Python Console editor and use Autocomplete to see the available properties of a given class, e.g. typing bpy.context.scene. and pressing Ctrl+Space will reveal:

>>> bpy.context.scene.
NWBusyDrawing
NWLazySource
NWLazyTarget
NWSourceSocket
active_clip
active_layer
alembic_export(
animation_data
animation_data_clear(
animation_data_create(
as_pointer(
audio_distance_model
audio_doppler_factor
audio_doppler_speed
audio_volume
etc......
etc....
etc..

• Epic! Thank you Ray :) It sucks being a noob. – allen Feb 17 '17 at 19:09

I ran into this same problem and tried Ray's above method, but no matter which parameters I supplied, i.e. 8 px vs 16 px, the resulting UV map showed no difference.

After a lot of tinkering I found that the proper line to access the Margin property is:

bpy.data.scenes["Scene"].render.bake_margin = 8

• My answer still works for me. All that using bpy.data.scenes["Scene"] does instead of bpy.context.scene is that it uses a specific scene ('Scene'), instead of the current one. – Ray Mairlot Jun 21 '17 at 17:38