PyAPI: add Context.temp_override documentation & examples

Add a new section to the `Context` page that includes an explanation
on how to invoke "on demand" logging for context member access.

Design task: #144746
Logging added in: !144810

Ref !146862
This commit is contained in:
Nick Alberelli
2025-10-08 05:07:39 +00:00
committed by Campbell Barton
parent f222916c38
commit 0d9ea9d11c
2 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
"""
Logging Context Member Access
+++++++++++++++++++++++++++++
Context members can be logged by calling ``logging_set(True)`` on the "with" target of a temporary override.
This will log the members that are being accessed during the operation and may
assist in debugging when it is unclear which members need to be overridden.
In the event an operator fails to execute because of a missing context member, logging may help
identify which member is required.
This example shows how to log which context members are being accessed.
Log statements are printed to your system's console.
.. important::
Not all operators rely on Context Members and therefore will not be affected by
:class:`bpy.types.Context.temp_override`, use logging to what members if any are accessed.
"""
import bpy
from bpy import context
my_objects = [context.scene.camera]
with context.temp_override(selected_objects=my_objects) as override:
override.logging_set(True) # Enable logging.
bpy.ops.object.delete()