[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46187] trunk/blender/doc/python_api/ examples: Python: documentation about overriding context members.

Brecht Van Lommel brechtvanlommel at pandora.be
Wed May 2 15:28:13 CEST 2012


Revision: 46187
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46187
Author:   blendix
Date:     2012-05-02 13:28:13 +0000 (Wed, 02 May 2012)
Log Message:
-----------
Python: documentation about overriding context members.

Added Paths:
-----------
    trunk/blender/doc/python_api/examples/bpy.ops.2.py
    trunk/blender/doc/python_api/examples/bpy.ops.3.py

Added: trunk/blender/doc/python_api/examples/bpy.ops.2.py
===================================================================
--- trunk/blender/doc/python_api/examples/bpy.ops.2.py	                        (rev 0)
+++ trunk/blender/doc/python_api/examples/bpy.ops.2.py	2012-05-02 13:28:13 UTC (rev 46187)
@@ -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)
+

Added: trunk/blender/doc/python_api/examples/bpy.ops.3.py
===================================================================
--- trunk/blender/doc/python_api/examples/bpy.ops.3.py	                        (rev 0)
+++ trunk/blender/doc/python_api/examples/bpy.ops.3.py	2012-05-02 13:28:13 UTC (rev 46187)
@@ -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
+




More information about the Bf-blender-cvs mailing list