[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2876] contrib/py/scripts/addons/ space_view3d_add_surround_cameras.py: replace use of bpy.ops.object. select_name()

Campbell Barton ideasman42 at gmail.com
Wed Jan 11 05:01:27 CET 2012


Revision: 2876
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2876
Author:   campbellbarton
Date:     2012-01-11 04:01:18 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
replace use of bpy.ops.object.select_name()

Modified Paths:
--------------
    contrib/py/scripts/addons/space_view3d_add_surround_cameras.py

Modified: contrib/py/scripts/addons/space_view3d_add_surround_cameras.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_add_surround_cameras.py	2012-01-10 23:47:31 UTC (rev 2875)
+++ contrib/py/scripts/addons/space_view3d_add_surround_cameras.py	2012-01-11 04:01:18 UTC (rev 2876)
@@ -34,6 +34,8 @@
 from math import pi
 import re
 
+CAMERA_ORIGIN_NAME = "CameraOrigin"
+
 # property for how many screens to add
 bpy.types.WindowManager.num_surround_screens = IntProperty(
     name="Number of screens",
@@ -98,22 +100,16 @@
 
     def execute(self, context):
 
+        scene = context.scene
         numScreens = context.window_manager.num_surround_screens
 
         # add an empty for the camera origin if not already present
-        originExists = False
-        for object in bpy.data.objects:
-            if object.name == "CameraOrigin":
-                bpy.ops.object.select_name(name="CameraOrigin")
-                origin = context.active_object
-                originExists = True
-                break
-
-        if not originExists:
+        obj_origin = scene.objects.get(CAMERA_ORIGIN_NAME)
+        if not obj_origin:
             bpy.ops.object.add()
-            origin = context.active_object
-            origin.name = "CameraOrigin"
-            origin.location = context.scene.cursor_location
+            obj_origin = context.active_object
+            obj_origin.name = CAMERA_ORIGIN_NAME
+            obj_origin.location = scene.cursor_location
 
         for i in range(0,numScreens):
 
@@ -136,9 +132,13 @@
             cam.data.angle = (2*pi)/numScreens
 
             # make the parent of the camera the origin
-            cam.parent = origin
+            cam.parent = obj_origin
 
-        bpy.ops.object.select_name(name="CameraOrigin")
+        # sel/activate origin
+        bpy.ops.object.select_all(action='DESELECT')
+        obj_origin.select = True
+        scene.objects.active = obj_origin
+
         context.window_manager.previous_num_surround_screens = numScreens
         return {'FINISHED'}
 
@@ -220,13 +220,15 @@
         return False
 
     def execute(self, context):
-        numScreens = context.window_manager.previous_num_surround_screens
 
-        for object in bpy.data.objects:
-            if object.type == 'CAMERA':
-                bpy.ops.object.select_name(name=object.name)
-                bpy.ops.object.delete()
+        scene = context.scene
 
+        # XXX. shouldnt there be some less general way to do this?
+        # like check if they are the child of origin? - campbell
+        for obj in scene.objects[:]:
+            if obj.type == 'CAMERA':
+                scene.objects.unlink(obj)
+
         context.window_manager.previous_num_surround_screens = -1
         return {'FINISHED'}
 



More information about the Bf-extensions-cvs mailing list