[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54030] trunk/blender/release/scripts/ startup/bl_operators: code cleanup: dont use 'bpy.context' when 'context' is available

Campbell Barton ideasman42 at gmail.com
Wed Jan 23 08:52:36 CET 2013


Revision: 54030
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54030
Author:   campbellbarton
Date:     2013-01-23 07:52:31 +0000 (Wed, 23 Jan 2013)
Log Message:
-----------
code cleanup: dont use 'bpy.context' when 'context' is available

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/object_align.py
    trunk/blender/release/scripts/startup/bl_operators/object_quick_effects.py
    trunk/blender/release/scripts/startup/bl_operators/object_randomize_transform.py
    trunk/blender/release/scripts/startup/bl_operators/rigidbody.py
    trunk/blender/release/scripts/startup/bl_operators/uvcalc_lightmap.py
    trunk/blender/release/scripts/startup/bl_operators/wm.py

Modified: trunk/blender/release/scripts/startup/bl_operators/object_align.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/object_align.py	2013-01-23 07:42:28 UTC (rev 54029)
+++ trunk/blender/release/scripts/startup/bl_operators/object_align.py	2013-01-23 07:52:31 UTC (rev 54030)
@@ -114,14 +114,15 @@
     return Vector((left, front, up)), Vector((right, back, down))
 
 
-def align_objects(align_x,
+def align_objects(context,
+                  align_x,
                   align_y,
                   align_z,
                   align_mode,
                   relative_to,
                   bb_quality):
 
-    cursor = bpy.context.scene.cursor_location
+    cursor = context.scene.cursor_location
 
     Left_Front_Up_SEL = [0.0, 0.0, 0.0]
     Right_Back_Down_SEL = [0.0, 0.0, 0.0]
@@ -130,7 +131,7 @@
 
     objs = []
 
-    for obj in bpy.context.selected_objects:
+    for obj in context.selected_objects:
         matrix_world = obj.matrix_world.copy()
         bb_world = [matrix_world * Vector(v[:]) for v in obj.bound_box]
         objs.append((obj, bb_world))
@@ -150,7 +151,7 @@
 
         # Active Center
 
-        if obj == bpy.context.active_object:
+        if obj == context.active_object:
 
             center_active_x = (Left_Front_Up[0] + Right_Back_Down[0]) / 2.0
             center_active_y = (Left_Front_Up[1] + Right_Back_Down[1]) / 2.0
@@ -386,7 +387,8 @@
 
     def execute(self, context):
         align_axis = self.align_axis
-        ret = align_objects('X' in align_axis,
+        ret = align_objects(context,
+                            'X' in align_axis,
                             'Y' in align_axis,
                             'Z' in align_axis,
                             self.align_mode,

Modified: trunk/blender/release/scripts/startup/bl_operators/object_quick_effects.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/object_quick_effects.py	2013-01-23 07:42:28 UTC (rev 54029)
+++ trunk/blender/release/scripts/startup/bl_operators/object_quick_effects.py	2013-01-23 07:52:31 UTC (rev 54030)
@@ -72,7 +72,7 @@
             )
 
     def execute(self, context):
-        fake_context = bpy.context.copy()
+        fake_context = context.copy()
         mesh_objects = [obj for obj in context.selected_objects
                         if obj.type == 'MESH']
 
@@ -161,7 +161,7 @@
             )
 
     def execute(self, context):
-        fake_context = bpy.context.copy()
+        fake_context = context.copy()
         obj_act = context.active_object
 
         if obj_act is None or obj_act.type != 'MESH':
@@ -311,7 +311,7 @@
             )
 
     def execute(self, context):
-        fake_context = bpy.context.copy()
+        fake_context = context.copy()
         mesh_objects = [obj for obj in context.selected_objects
                         if obj.type == 'MESH']
         min_co = Vector((100000.0, 100000.0, 100000.0))
@@ -432,7 +432,7 @@
             )
 
     def execute(self, context):
-        fake_context = bpy.context.copy()
+        fake_context = context.copy()
         mesh_objects = [obj for obj in context.selected_objects
                         if (obj.type == 'MESH' and not 0.0 in obj.dimensions)]
         min_co = Vector((100000, 100000, 100000))

Modified: trunk/blender/release/scripts/startup/bl_operators/object_randomize_transform.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/object_randomize_transform.py	2013-01-23 07:42:28 UTC (rev 54029)
+++ trunk/blender/release/scripts/startup/bl_operators/object_randomize_transform.py	2013-01-23 07:52:31 UTC (rev 54030)
@@ -23,7 +23,8 @@
 from mathutils import Vector
 
 
-def randomize_selected(seed, delta, loc, rot, scale, scale_even, scale_min):
+def randomize_selected(context, seed, delta,
+                       loc, rot, scale, scale_even, scale_min):
 
     import random
     from random import uniform
@@ -33,7 +34,7 @@
     def rand_vec(vec_range):
         return Vector(uniform(-val, val) for val in vec_range)
 
-    for obj in bpy.context.selected_objects:
+    for obj in context.selected_objects:
 
         if loc:
             if delta:
@@ -180,6 +181,7 @@
         #scale_min = self.scale_min
         scale_min = 0
 
-        randomize_selected(seed, delta, loc, rot, scale, scale_even, scale_min)
+        randomize_selected(context, seed, delta,
+                           loc, rot, scale, scale_even, scale_min)
 
         return {'FINISHED'}

Modified: trunk/blender/release/scripts/startup/bl_operators/rigidbody.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/rigidbody.py	2013-01-23 07:42:28 UTC (rev 54029)
+++ trunk/blender/release/scripts/startup/bl_operators/rigidbody.py	2013-01-23 07:52:31 UTC (rev 54030)
@@ -32,7 +32,7 @@
 
     @classmethod
     def poll(cls, context):
-        obj = bpy.context.object
+        obj = context.object
         return (obj and obj.rigid_body)
 
     def execute(self, context):
@@ -101,22 +101,22 @@
 
     @classmethod
     def poll(cls, context):
-        obj = bpy.context.object
+        obj = context.object
         return (obj and obj.rigid_body)
 
     def execute(self, context):
         bake = []
         objs = []
-        scene = bpy.context.scene
+        scene = context.scene
         frame_orig = scene.frame_current
         frames = list(range(self.frame_start, self.frame_end + 1, self.step))
 
         # filter objects selection
-        for ob in bpy.context.selected_objects:
-            if not ob.rigid_body or ob.rigid_body.type != 'ACTIVE':
-                ob.select = False
+        for obj in context.selected_objects:
+            if not obj.rigid_body or obj.rigid_body.type != 'ACTIVE':
+                obj.select = False
 
-        objs = bpy.context.selected_objects
+        objs = context.selected_objects
 
         if objs:
             # store transformation data
@@ -124,31 +124,31 @@
                 scene.frame_set(f)
                 if f in frames:
                     mat = {}
-                    for i, ob in enumerate(objs):
-                        mat[i] = ob.matrix_world.copy()
+                    for i, obj in enumerate(objs):
+                        mat[i] = obj.matrix_world.copy()
                     bake.append(mat)
 
             # apply transformations as keyframes
             for i, f in enumerate(frames):
                 scene.frame_set(f)
-                ob_prev = objs[0]
-                for j, ob in enumerate(objs):
+                obj_prev = objs[0]
+                for j, obj in enumerate(objs):
                     mat = bake[i][j]
 
-                    ob.location = mat.to_translation()
+                    obj.location = mat.to_translation()
 
-                    rot_mode = ob.rotation_mode
+                    rot_mode = obj.rotation_mode
                     if rot_mode == 'QUATERNION':
-                        ob.rotation_quaternion = mat.to_quaternion()
+                        obj.rotation_quaternion = mat.to_quaternion()
                     elif rot_mode == 'AXIS_ANGLE':
                         # this is a little roundabout but there's no better way right now
                         aa = mat.to_quaternion().to_axis_angle()
-                        ob.rotation_axis_angle = (aa[1], ) + aa[0][:]
+                        obj.rotation_axis_angle = (aa[1], ) + aa[0][:]
                     else: # euler
                         # make sure euler rotation is compatible to previous frame
-                        ob.rotation_euler = mat.to_euler(rot_mode, ob_prev.rotation_euler)
+                        obj.rotation_euler = mat.to_euler(rot_mode, obj_prev.rotation_euler)
 
-                    ob_prev = ob
+                    obj_prev = obj
 
                 bpy.ops.anim.keyframe_insert(type='BUILTIN_KSI_LocRot', confirm_success=False)
 
@@ -156,8 +156,8 @@
             bpy.ops.rigidbody.objects_remove()
 
             # clean up keyframes
-            for ob in objs:
-                action = ob.animation_data.action
+            for obj in objs:
+                action = obj.animation_data.action
                 for fcu in action.fcurves:
                     keyframe_points = fcu.keyframe_points
                     i = 1
@@ -219,30 +219,30 @@
 
     @classmethod
     def poll(cls, context):
-        obj = bpy.context.object
-        objs = bpy.context.selected_objects
+        obj = context.object
+        objs = context.selected_objects
         return (obj and obj.rigid_body and (len(objs) > 1))
 
     def execute(self, context):
 
-        objs = bpy.context.selected_objects
-        ob_act = bpy.context.active_object
+        objs = context.selected_objects
+        obj_act = context.active_object
 
-        for ob in objs:
-            if ob == ob_act:
+        for obj in objs:
+            if obj == obj_act:
                 continue
             if self.pivot_type == 'ACTIVE':
-                loc = ob_act.location
+                loc = obj_act.location
             elif self.pivot_type == 'SELECTED':
-                loc = ob.location
+                loc = obj.location
             else:
-                loc = (ob_act.location + ob.location) / 2
+                loc = (obj_act.location + obj.location) / 2.0
             bpy.ops.object.add(type='EMPTY', view_align=False, enter_editmode=False, location=loc)
             bpy.ops.rigidbody.constraint_group_add()
-            con = bpy.context.active_object.rigid_body_constraint
+            con = context.active_object.rigid_body_constraint
             con.type = self.con_type
-            con.object1 = ob_act
-            con.object2 = ob
+            con.object1 = obj_act
+            con.object2 = obj
 
         return {'FINISHED'}
 

Modified: trunk/blender/release/scripts/startup/bl_operators/uvcalc_lightmap.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/uvcalc_lightmap.py	2013-01-23 07:42:28 UTC (rev 54029)
+++ trunk/blender/release/scripts/startup/bl_operators/uvcalc_lightmap.py	2013-01-23 07:52:31 UTC (rev 54030)
@@ -516,7 +516,7 @@
 
 def unwrap(operator, context, **kwargs):
 
-    is_editmode = (bpy.context.object.mode == 'EDIT')
+    is_editmode = (context.object.mode == 'EDIT')

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list