[Bf-extensions-cvs] [2e2199f] master: Use of the ObjectSelection context manager ensures that the current selection is restored after running operators.

Lukas Tönne noreply at git.blender.org
Wed Dec 10 15:01:01 CET 2014


Commit: 2e2199f383ad404c164e3951697af8e6ab9aecb4
Author: Lukas Tönne
Date:   Wed Dec 10 15:00:24 2014 +0100
Branches: master
https://developer.blender.org/rBAC2e2199f383ad404c164e3951697af8e6ab9aecb4

Use of the ObjectSelection context manager ensures that the current
selection is restored after running operators.

===================================================================

M	object_physics_meadow/patch.py
M	object_physics_meadow/ui.py

===================================================================

diff --git a/object_physics_meadow/patch.py b/object_physics_meadow/patch.py
index f00c274..9c035df 100644
--- a/object_physics_meadow/patch.py
+++ b/object_physics_meadow/patch.py
@@ -129,30 +129,29 @@ def make_patches(context, gridob, template_objects):
     patch_group_clear(context)
     
     temp_copies = {}
-    with ObjectSelection():
-        for tempob in template_objects:
-            # create patch copies
-            copies = make_copies(scene, gridob, tempob)
+    for tempob in template_objects:
+        # create patch copies
+        copies = make_copies(scene, gridob, tempob)
+        
+        # customize copies
+        for ob, (index, vert) in zip(copies, enumerate(gridob.data.vertices)):
+            # put it in the patch group
+            patch_group_assign(context, ob)
+            # assign the index for mapping
+            ob.meadow.blob_index = index
             
-            # customize copies
-            for ob, (index, vert) in zip(copies, enumerate(gridob.data.vertices)):
-                # put it in the patch group
-                patch_group_assign(context, ob)
-                # assign the index for mapping
-                ob.meadow.blob_index = index
-                
-                # apply transform
-                vertmat = Matrix.Translation(vert.co)
-                duplimat = gridmat * vertmat
-                ob.matrix_world = duplimat
-                
-                # XXX WARNING: having lots of objects in the scene slows down
-                # the make-duplis-real operator to an absolute crawl!!
-                # Therefore we unlink all copies here until the copying
-                # of other objects is done
-                scene.objects.unlink(ob)
+            # apply transform
+            vertmat = Matrix.Translation(vert.co)
+            duplimat = gridmat * vertmat
+            ob.matrix_world = duplimat
             
-            temp_copies[tempob] = copies
+            # XXX WARNING: having lots of objects in the scene slows down
+            # the make-duplis-real operator to an absolute crawl!!
+            # Therefore we unlink all copies here until the copying
+            # of other objects is done
+            scene.objects.unlink(ob)
+        
+        temp_copies[tempob] = copies
     
     # copying is done, re-link stuff to the scene
     for tempob, copies in temp_copies.items():
@@ -281,15 +280,14 @@ def patch_objects_rebake(context):
     settings = _settings.get(context)
     wm = context.window_manager
     
-    with ObjectSelection():
-        # we disable all sim modifiers selectively to make sure only one sim has to be calculated at a time
-        with BakeSimContext():
-            scene = context.scene
-            curframe = scene.frame_current
-            
-            # XXX have to set this because bake operator only bakes up to the last frame ...
-            scene.frame_current = scene.frame_end
-            
-            bake_all(context)
-            
-            scene.frame_set(curframe)
+    # we disable all sim modifiers selectively to make sure only one sim has to be calculated at a time
+    with BakeSimContext():
+        scene = context.scene
+        curframe = scene.frame_current
+        
+        # XXX have to set this because bake operator only bakes up to the last frame ...
+        scene.frame_current = scene.frame_end
+        
+        bake_all(context)
+        
+        scene.frame_set(curframe)
diff --git a/object_physics_meadow/ui.py b/object_physics_meadow/ui.py
index 834507e..b032a7b 100644
--- a/object_physics_meadow/ui.py
+++ b/object_physics_meadow/ui.py
@@ -24,6 +24,7 @@ from bpy.props import *
 
 from object_physics_meadow import meadow, settings as _settings, patch, blob
 from object_physics_meadow.settings import find_meadow_object
+from object_physics_meadow.util import *
 
 class OBJECT_PT_Meadow(Panel):
     """Settings for meadow components"""
@@ -133,7 +134,8 @@ class MakeBlobsOperator(MeadowOperatorBase, Operator):
             self.report({'ERROR'}, "Could not find meadow Blob Grid object")
             return {'CANCELLED'}
         
-        meadow.make_blobs(context, blobgridob, groundob)
+        with ObjectSelection():
+            meadow.make_blobs(context, blobgridob, groundob)
         
         return {'FINISHED'}
 
@@ -162,7 +164,8 @@ class MakePatchesOperator(MeadowOperatorBase, Operator):
             self.report({'ERROR'}, "Could not find meadow Blob Grid object")
             return {'CANCELLED'}
         
-        meadow.make_patches(context, blobgridob, groundob)
+        with ObjectSelection():
+            meadow.make_patches(context, blobgridob, groundob)
         
         return {'FINISHED'}
 
@@ -192,7 +195,8 @@ class RebakeMeadowOperator(MeadowOperatorBase, Operator):
     bl_options = {'REGISTER', 'UNDO'}
     
     def execute(self, context):
-        patch.patch_objects_rebake(context)
+        with ObjectSelection():
+            patch.patch_objects_rebake(context)
         return {'FINISHED'}



More information about the Bf-extensions-cvs mailing list