[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3811] contrib/py/scripts/addons/ space_view3d_paint_bprojection.py: Replaced names for Material, Empty and Texture by constants (WIP)

Gaia Clary gaia.clary at machinimatrix.org
Thu Oct 4 11:13:54 CEST 2012


Revision: 3811
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3811
Author:   gaiaclary
Date:     2012-10-04 09:13:53 +0000 (Thu, 04 Oct 2012)
Log Message:
-----------
Replaced names for Material, Empty and Texture by constants (WIP)

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

Modified: contrib/py/scripts/addons/space_view3d_paint_bprojection.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_paint_bprojection.py	2012-10-04 01:36:24 UTC (rev 3810)
+++ contrib/py/scripts/addons/space_view3d_paint_bprojection.py	2012-10-04 09:13:53 UTC (rev 3811)
@@ -17,10 +17,14 @@
 import mathutils
 from mathutils import *
 
+BProjection_Empty    = 'Empty for BProjection'
+BProjection_Material = 'Material for BProjection'
+BProjection_Texture  = 'Texture for BProjection'
+
 # Main function for align the plan to view
 def align_to_view(context):
     ob = context.object
-    em = bpy.data.objects['Empty for BProjection']       
+    em = bpy.data.objects[BProjection_Empty]       
     rotation = em.custom_rotation
     scale = em.custom_scale
     z = em.custom_location.z
@@ -38,8 +42,8 @@
     v = Vector((pos[0],pos[1],z))
     v.rotate(vr)
 
-    em = bpy.data.objects['Empty for BProjection']
-    img = bpy.data.textures['Texture for BProjection'].image
+    em = bpy.data.objects[BProjection_Empty]
+    img = bpy.data.textures[BProjection_Texture].image
     if img and img.size[1] != 0:
         prop = img.size[0]/img.size[1]
     else: prop = 1    
@@ -63,8 +67,8 @@
         sd.cursor_location =  v
 
 def applyimage(context):        
-        img = bpy.data.textures['Texture for BProjection'].image
-        em = bpy.data.objects['Empty for BProjection']
+        img = bpy.data.textures[BProjection_Texture].image
+        em = bpy.data.objects[BProjection_Empty]
         ob = context.object
                
         face = ob.data.polygons
@@ -104,7 +108,7 @@
 # Function to update the scaleUV
 def update_UVScale(self, context):
     ob = context.object
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     v = Vector((em.custom_offsetuv[0]/10 + 0.5, em.custom_offsetuv[1]/10 + 0.5))
     l = Vector((0.0,0.0))
     s = em.custom_scaleuv
@@ -123,12 +127,12 @@
     applyimage(context)
 
 def update_PropUVScale(self, context):
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     if em.custom_linkscaleuv:
         em.custom_scaleuv = [em.custom_propscaleuv,em.custom_propscaleuv]
 
 def update_LinkUVScale(self, context):
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     if em.custom_linkscaleuv:
         em.custom_propscaleuv = em.custom_scaleuv.x
         update_PropUVScale(self, context)
@@ -138,7 +142,7 @@
 # Function to update the offsetUV
 def update_UVOffset(self, context):
     ob = context.object
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     o = em.custom_offsetuv
     oo = em.custom_old_offsetuv 
     l = find_uv(context)
@@ -175,13 +179,13 @@
 # Function to update
 def update_Rotation(self, context):              
     ob = context.object
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     if em.custom_rotc3d:
         angle = em.custom_rotation - em.custom_old_rotation
         sd = context.space_data
         vr = sd.region_3d.view_rotation.copy()        
         c = sd.cursor_location - ob.location
-        e = bpy.data.objects['Empty for BProjection'].location - ob.location
+        e = bpy.data.objects[BProjection_Empty].location - ob.location
         vo = Vector((0.0, 0.0, 1.0))
         vo.rotate(vr)
         quat = mathutils.Quaternion(vo, math.radians(angle))
@@ -199,7 +203,7 @@
 # Function to update scale
 def update_Scale(self, context):              
     ob = context.object
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     
     if em.custom_scac3d:
         sd = context.space_data
@@ -215,7 +219,7 @@
         c.rotate(vr)
         ce.rotate(vr)
         
-        img = bpy.data.textures['Texture for BProjection'].image
+        img = bpy.data.textures[BProjection_Texture].image
         if img and img.size[1] != 0:
             prop = img.size[0]/img.size[1]
         else: prop = 1
@@ -231,12 +235,12 @@
     em.custom_old_scale = em.custom_scale
 
 def update_PropScale(self, context):
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     if em.custom_linkscale:
         em.custom_scale = [em.custom_propscale,em.custom_propscale]
     
 def update_LinkScale(self, context):
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     if em.custom_linkscale:
         em.custom_propscale = em.custom_scale.x
         update_PropScale(self, context)
@@ -244,7 +248,7 @@
         update_Scale(self, context) 
 
 def update_activeviewname(self, context):
-    em = bpy.data.objects['Empty for BProjection']
+    em = bpy.data.objects[BProjection_Empty]
     if self.custom_active:
         em.custom_active_view = self.custom_active_view
 
@@ -347,12 +351,12 @@
                  'custom_expand', 'custom_active_view', 'custom_propscaleuv', 'custom_props', 'custom_propscale']
     for prop in list_prop:
         try:
-            del bpy.data.objects['Empty for BProjection'][prop]
+            del bpy.data.objects[BProjection_Empty][prop]
         except:
             pass
         
 def clear_props(context):
-    em = bpy.data.objects['Empty for BProjection'] 
+    em = bpy.data.objects[BProjection_Empty] 
     em.custom_scale = [1,1]
     em.custom_rotation = 0
     em.custom_scaleuv =[1.0,1.0]
@@ -371,7 +375,7 @@
 
     def execute(self, context):              
         ob = context.object
-        em = bpy.data.objects['Empty for BProjection']
+        em = bpy.data.objects[BProjection_Empty]
         new_props = em.custom_props.add()        
         em.custom_active_view = new_props.custom_active_view               
         ob.data.shape_keys.key_blocks[ob.active_shape_key_index].mute = True
@@ -389,7 +393,7 @@
     index = IntProperty(default = 0)
     
     def execute(self, context):              
-        em = bpy.data.objects['Empty for BProjection']
+        em = bpy.data.objects[BProjection_Empty]
         prop = em.custom_props[self.index]                            
         prop.custom_rotation =  em.custom_rotation                    
         prop.custom_scale =  em.custom_scale                  
@@ -402,7 +406,7 @@
         prop.custom_flipuvx = em.custom_flipuvx
         prop.custom_flipuvy = em.custom_flipuvy
         try:
-            prop.custom_image = bpy.data.textures['Texture for BProjection'].image.name
+            prop.custom_image = bpy.data.textures[BProjection_Texture].image.name
         except:
             pass
         
@@ -416,7 +420,7 @@
     index = IntProperty(default = 0)
     
     def execute(self, context):              
-        em = bpy.data.objects['Empty for BProjection']
+        em = bpy.data.objects[BProjection_Empty]
         tmp_scac3d = em.custom_scac3d
         tmp_rotc3d = em.custom_rotc3d
         em.custom_scac3d = False
@@ -431,8 +435,8 @@
         em.custom_scale =  prop.custom_scale
         em.custom_propscale = prop.custom_propscale                     
         if prop.custom_image != '':
-            if bpy.data.textures['Texture for BProjection'].image.name != prop.custom_image:
-                bpy.data.textures['Texture for BProjection'].image = bpy.data.images[prop.custom_image]
+            if bpy.data.textures[BProjection_Texture].image.name != prop.custom_image:
+                bpy.data.textures[BProjection_Texture].image = bpy.data.images[prop.custom_image]
                 applyimage(context)
         if em.custom_flipuvx != prop.custom_flipuvx:
             em.custom_flipuvx = prop.custom_flipuvx
@@ -451,7 +455,7 @@
     
     def execute(self, context):              
         ob = context.object
-        em = bpy.data.objects['Empty for BProjection']
+        em = bpy.data.objects[BProjection_Empty]
         
         ob.active_shape_key_index =  self.index + 1
         bpy.ops.object.shape_key_remove()
@@ -488,7 +492,7 @@
     
     def execute(self, context):
         ob = context.object
-        em = bpy.data.objects['Empty for BProjection']
+        em = bpy.data.objects[BProjection_Empty]
         for item in (item for item in em.custom_props if item.custom_active == True):
             bpy.ops.object.save_view(index = item.custom_index)
             item.custom_active = False
@@ -515,14 +519,13 @@
     def poll(cls, context):
         return (context.image_paint_object or context.sculpt_object)
 
-    def draw(self, context):        
+    def draw(self, context):
         layout = self.layout        
-        if  'Empty for BProjection' in [ob.name for ob in bpy.data.objects]:
-            
-            
-            tex = bpy.data.textures['Texture for BProjection']
+        if  BProjection_Empty in [ob.name for ob in bpy.data.objects]:
+            tex = bpy.data.textures[BProjection_Texture]
+
             ob = context.object
-            em = bpy.data.objects['Empty for BProjection']
+            em = bpy.data.objects[BProjection_Empty]
             if ob == bpy.data.objects[em.custom_active_object]:            
                 col = layout.column(align =True)
                 col.operator("object.removebprojectionplane", text="Remove BProjection plane")           
@@ -620,7 +623,7 @@
 
     def invoke(self, context, event):
         ob = context.object
-        em = bpy.data.objects['Empty for BProjection']
+        em = bpy.data.objects[BProjection_Empty]
         x = event.mouse_region_x
         y = event.mouse_region_y                
         if len(ob.grease_pencil.layers.active.frames) == 0: 
@@ -687,7 +690,7 @@
         ob.data.update()
             
     def execute(self, context):    
-        if  'Empty for BProjection' not in [ob.name for ob in bpy.data.objects]:                
+        if  BProjection_Empty not in [ob.name for ob in bpy.data.objects]:                
             
             cm = bpy.context.object.mode
             '''tmp = context.object
@@ -704,7 +707,7 @@
         
             bpy.ops.object.add()
             em = context.object
-            em.name = "Empty for BProjection"
+            em.name = BProjection_Empty
                         
             context.scene.objects.active = ob
             ob.select = True
@@ -775,7 +778,7 @@
             context.space_data.cursor_location = em.location

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list