Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-05-02 17:28:13 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-05-02 17:28:13 +0400
commit2151c2f28efff1394a7e315240c1835326e66233 (patch)
treef9c1a2e75b03e391bce22829bc45ccbc1185044c /doc
parent4fd18b5d3c211b153cfab0996b616df019527f68 (diff)
Python: documentation about overriding context members.
Diffstat (limited to 'doc')
-rw-r--r--doc/python_api/examples/bpy.ops.2.py18
-rw-r--r--doc/python_api/examples/bpy.ops.3.py18
2 files changed, 36 insertions, 0 deletions
diff --git a/doc/python_api/examples/bpy.ops.2.py b/doc/python_api/examples/bpy.ops.2.py
new file mode 100644
index 00000000000..86b7438888c
--- /dev/null
+++ b/doc/python_api/examples/bpy.ops.2.py
@@ -0,0 +1,18 @@
+"""
+Overriding Context
+++++++++++++++++++
+
+It is possible to override context members that the operator sees, so that they
+act on specified rather than the selected or active data, or to execute an
+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}.
+"""
+
+# remove all objects in scene rather than the selected ones
+import bpy
+override = {'selected_bases': list(bpy.context.scene.object_bases)}
+bpy.ops.object.delete(override)
+
diff --git a/doc/python_api/examples/bpy.ops.3.py b/doc/python_api/examples/bpy.ops.3.py
new file mode 100644
index 00000000000..0b5bcafe5be
--- /dev/null
+++ b/doc/python_api/examples/bpy.ops.3.py
@@ -0,0 +1,18 @@
+"""
+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.
+"""
+
+# maximize 3d view in all windows
+import bpy
+
+for window in bpy.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)
+ break
+