From 9364e17936969ad147198ee1bb54eb4dae5e8dab Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 20 Apr 2022 12:49:13 +1000 Subject: Docs: update examples to use Context.temp_override --- doc/python_api/examples/bpy.ops.1.py | 12 +++++++----- doc/python_api/examples/bpy.ops.3.py | 13 ++++++------- doc/python_api/examples/bpy.ops.py | 5 +++++ 3 files changed, 18 insertions(+), 12 deletions(-) (limited to 'doc/python_api') diff --git a/doc/python_api/examples/bpy.ops.1.py b/doc/python_api/examples/bpy.ops.1.py index efc9f00b0ae..9b690823a18 100644 --- a/doc/python_api/examples/bpy.ops.1.py +++ b/doc/python_api/examples/bpy.ops.1.py @@ -9,7 +9,7 @@ operator in the different part of the user interface. The context overrides are passed as a dictionary, with keys matching the context member names in bpy.context. For example to override ``bpy.context.active_object``, -you would pass ``{'active_object': object}``. +you would pass ``{'active_object': object}`` to :class:`bpy.types.Context.temp_override`. .. note:: @@ -17,8 +17,10 @@ you would pass ``{'active_object': object}``. (otherwise, you'll have to find and gather all needed data yourself). """ -# remove all objects in scene rather than the selected ones +# Remove all objects in scene rather than the selected ones. import bpy -override = bpy.context.copy() -override['selected_objects'] = list(bpy.context.scene.objects) -bpy.ops.object.delete(override) +from bpy import context +override = context.copy() +override["selected_objects"] = list(context.scene.objects) +with context.temp_override(**override): + bpy.ops.object.delete() diff --git a/doc/python_api/examples/bpy.ops.3.py b/doc/python_api/examples/bpy.ops.3.py index 7dec69cf566..e068ab0c0cf 100644 --- a/doc/python_api/examples/bpy.ops.3.py +++ b/doc/python_api/examples/bpy.ops.3.py @@ -1,17 +1,16 @@ """ It is also possible to run an operator in a particular part of the user -interface. For this we need to pass the window, screen, area and sometimes -a region. +interface. For this we need to pass the window, area and sometimes a region. """ -# maximize 3d view in all windows +# Maximize 3d view in all windows. import bpy +from bpy import context -for window in bpy.context.window_manager.windows: +for window in context.window_manager.windows: screen = window.screen - for area in screen.areas: if area.type == 'VIEW_3D': - override = {'window': window, 'screen': screen, 'area': area} - bpy.ops.screen.screen_full_area(override) + with context.temp_override(window=window, area=area): + bpy.ops.screen.screen_full_area() break diff --git a/doc/python_api/examples/bpy.ops.py b/doc/python_api/examples/bpy.ops.py index 76c494ad4f5..e8d545fc855 100644 --- a/doc/python_api/examples/bpy.ops.py +++ b/doc/python_api/examples/bpy.ops.py @@ -33,6 +33,11 @@ There are 3 optional positional arguments (documented in detail below). bpy.ops.test.operator(override_context, execution_context, undo) - override_context - ``dict`` type. + + .. deprecated:: 3.2 + + :class:`bpy.types.Context.temp_override` should be used instead of this argument. + - execution_context - ``str`` (enum). - undo - ``bool`` type. -- cgit v1.2.3