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:
committed by
Campbell Barton
parent
f222916c38
commit
0d9ea9d11c
28
doc/python_api/examples/bpy.types.Context.temp_override.4.py
Normal file
28
doc/python_api/examples/bpy.types.Context.temp_override.4.py
Normal 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()
|
||||
@@ -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 <blender_manual:command-line-args-logging-options>` can help.
|
||||
|
||||
|
||||
The operator still doesn't work!
|
||||
================================
|
||||
|
||||
Reference in New Issue
Block a user