From 0d9ea9d11c2986b705f20195570fb2407020b33d Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Wed, 8 Oct 2025 05:07:39 +0000 Subject: [PATCH] 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 --- .../bpy.types.Context.temp_override.4.py | 28 +++++++++++++++++++ doc/python_api/rst/info_gotchas_operators.rst | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 doc/python_api/examples/bpy.types.Context.temp_override.4.py diff --git a/doc/python_api/examples/bpy.types.Context.temp_override.4.py b/doc/python_api/examples/bpy.types.Context.temp_override.4.py new file mode 100644 index 00000000000..70dc20ad00f --- /dev/null +++ b/doc/python_api/examples/bpy.types.Context.temp_override.4.py @@ -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() diff --git a/doc/python_api/rst/info_gotchas_operators.rst b/doc/python_api/rst/info_gotchas_operators.rst index fb70704cd12..2a61f5af940 100644 --- a/doc/python_api/rst/info_gotchas_operators.rst +++ b/doc/python_api/rst/info_gotchas_operators.rst @@ -48,6 +48,9 @@ you should be able to find the poll function with no knowledge of C. >>> bpy.ops.gpencil.draw() RuntimeError: Operator bpy.ops.gpencil.draw.poll() Failed to find Grease Pencil data to draw into + In some cases using :class:`bpy.types.Context.temp_override` to enable temporary logging or using the + ``context`` category when :ref:`logging ` can help. + The operator still doesn't work! ================================