diff options
Diffstat (limited to 'doc/python_api/examples/bpy.types.Context.temp_override.2.py')
-rw-r--r-- | doc/python_api/examples/bpy.types.Context.temp_override.2.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/python_api/examples/bpy.types.Context.temp_override.2.py b/doc/python_api/examples/bpy.types.Context.temp_override.2.py new file mode 100644 index 00000000000..ce3e1594baa --- /dev/null +++ b/doc/python_api/examples/bpy.types.Context.temp_override.2.py @@ -0,0 +1,15 @@ +""" +Overriding the context can be useful to set the context after loading files +(which would otherwise by None). For example: +""" + +import bpy +from bpy import context + +# Reload the current file and select all. +bpy.ops.wm.open_mainfile(filepath=bpy.data.filepath) +window = context.window_manager.windows[0] +with context.temp_override(window=window): + bpy.ops.mesh.primitive_uv_sphere_add() + # The context override is needed so it's possible to set edit-mode. + bpy.ops.object.mode_set(mode='EDIT') |