BProjection: fix bug with keymap, and a bug, I actived shapekey before creating
authorGeo Kgeo <kgeogeo@hotmail.com>
Fri, 11 May 2012 20:19:39 +0000 (20:19 +0000)
committerGeo Kgeo <kgeogeo@hotmail.com>
Fri, 11 May 2012 20:19:39 +0000 (20:19 +0000)
space_view3d_paint_bprojection.py

index 3e34d303de714dbec730f5cfd3573ad3f5272233..8eacd54a16d4521477427fe014b19d8fece2730f 100644 (file)
@@ -354,14 +354,13 @@ class CreateView(Operator):
     def execute(self, context):              
         ob = context.object
         em = bpy.data.objects['Empty for BProjection']
-        new_props = em.custom_props.add()
-        
+        new_props = em.custom_props.add()        
         em.custom_active_view = new_props.custom_active_view               
-        new_props.custom_index = len(em.custom_props)-1
-        bpy.ops.object.active_view(index = new_props.custom_index)
         ob.data.shape_keys.key_blocks[ob.active_shape_key_index].mute = True
         bpy.ops.object.shape_key_add(from_mix = False)
         ob.data.shape_keys.key_blocks[ob.active_shape_key_index].value = 1.0
+        new_props.custom_index = len(em.custom_props)-1
+        bpy.ops.object.active_view(index = new_props.custom_index)
         return {'FINISHED'}
 
 # Oprerator Class to copy view 
@@ -593,31 +592,14 @@ class ApplyImage(Operator):
         img = bpy.data.textures['Texture for BProjection'].image
         em = bpy.data.objects['Empty for BProjection']
         ob = context.object
-        em = bpy.data.objects['Empty for BProjection']
-        cm = context.object.mode
                
-        bpy.ops.object.editmode_toggle()
-        f = ob.data.polygons
-        nbface = len(ob.data.polygons)
+        face = ob.data.polygons
         uvdata = ob.data.uv_textures.active.data 
-        wasnul = False
-        if len(uvdata) == 0:
-            bpy.ops.object.editmode_toggle()
-            uvdata = ob.data.uv_textures.active.data
-            wasnul = True                        
-        
-        
-        vglen = trunc(pow(em.custom_sub+1, 2))
-        
-        for i,d in zip(f,uvdata):
-            if i.select:
+            
+        for f,d in zip(face,uvdata):
+            if f.select:
                 d.image = img
-                        
-        if wasnul == False:
-            bpy.ops.object.editmode_toggle()
-        else:
-            bpy.ops.object.mode_set(mode = cm, toggle=False)
-                
+               
         align_to_view(context)
         
         return {'FINISHED'}
@@ -705,9 +687,9 @@ class AddBProjectionPlane(Operator):
             createcustomprops(context)
             cm = bpy.context.object.mode
             tmp = context.object
-            '''for ob in (ob for ob in bpy.data.objects if ob.type == 'MESH' and ob.hide == False and context.scene in ob.users_scene):
+            for ob in (ob for ob in bpy.data.objects if ob.type == 'MESH' and ob.hide == False and context.scene in ob.users_scene):
                 context.scene.objects.active = ob
-                bpy.ops.object.mode_set(mode = cm, toggle=False)''' 
+                bpy.ops.object.mode_set(mode = cm, toggle=False) 
             
             context.scene.objects.active = tmp
             bpy.ops.object.mode_set(mode = 'OBJECT', toggle=False)
@@ -767,18 +749,18 @@ class AddBProjectionPlane(Operator):
             km.keymap_items[20-1].idname = 'view3d.zoom_view3d'
             km.keymap_items[20-1].properties.delta = -1.0
             km.keymap_items[4-1].idname = 'view3d.pan_view3d'
-            km.keymap_items[26-1].idname = 'view3d.preset_view3d'
-            km.keymap_items[26-1].properties.view = 'FRONT'
             km.keymap_items[28-1].idname = 'view3d.preset_view3d'
-            km.keymap_items[28-1].properties.view = 'RIGHT'            
-            km.keymap_items[32-1].idname = 'view3d.preset_view3d'
-            km.keymap_items[32-1].properties.view = 'TOP'
+            km.keymap_items[28-1].properties.view = 'FRONT'
+            km.keymap_items[30-1].idname = 'view3d.preset_view3d'
+            km.keymap_items[30-1].properties.view = 'RIGHT'            
             km.keymap_items[34-1].idname = 'view3d.preset_view3d'
-            km.keymap_items[34-1].properties.view = 'BACK'
-            km.keymap_items[35-1].idname = 'view3d.preset_view3d'
-            km.keymap_items[35-1].properties.view = 'LEFT'            
+            km.keymap_items[34-1].properties.view = 'TOP'
             km.keymap_items[36-1].idname = 'view3d.preset_view3d'
-            km.keymap_items[36-1].properties.view = 'BOTTOM'                                   
+            km.keymap_items[36-1].properties.view = 'BACK'
+            km.keymap_items[37-1].idname = 'view3d.preset_view3d'
+            km.keymap_items[37-1].properties.view = 'LEFT'            
+            km.keymap_items[38-1].idname = 'view3d.preset_view3d'
+            km.keymap_items[38-1].properties.view = 'BOTTOM'                                   
             km = context.window_manager.keyconfigs.default.keymaps['Image Paint']
             kmi = km.keymap_items.new("object.intuitivescale", 'LEFTMOUSE', 'PRESS', shift=True)
                         
@@ -853,18 +835,18 @@ class RemoveBProjectionPlane(Operator):
             km.keymap_items[20-1].idname = 'view3d.zoom'
             km.keymap_items[20-1].properties.delta = -1.0
             km.keymap_items[4-1].idname = 'view3d.move'
-            km.keymap_items[26-1].idname = 'view3d.viewnumpad'
-            km.keymap_items[26-1].properties.type = 'FRONT'
             km.keymap_items[28-1].idname = 'view3d.viewnumpad'
-            km.keymap_items[28-1].properties.type = 'RIGHT'            
-            km.keymap_items[32-1].idname = 'view3d.viewnumpad'
-            km.keymap_items[32-1].properties.type = 'TOP'
+            km.keymap_items[28-1].properties.type = 'FRONT'
+            km.keymap_items[30-1].idname = 'view3d.viewnumpad'
+            km.keymap_items[30-1].properties.type = 'RIGHT'            
             km.keymap_items[34-1].idname = 'view3d.viewnumpad'
-            km.keymap_items[34-1].properties.type = 'BACK'
-            km.keymap_items[35-1].idname = 'view3d.viewnumpad'
-            km.keymap_items[35-1].properties.type = 'LEFT'            
+            km.keymap_items[34-1].properties.type = 'TOP'
             km.keymap_items[36-1].idname = 'view3d.viewnumpad'
-            km.keymap_items[36-1].properties.type = 'BOTTOM'            
+            km.keymap_items[36-1].properties.type = 'BACK'
+            km.keymap_items[37-1].idname = 'view3d.viewnumpad'
+            km.keymap_items[37-1].properties.type = 'LEFT'            
+            km.keymap_items[38-1].idname = 'view3d.viewnumpad'
+            km.keymap_items[38-1].properties.type = 'BOTTOM'            
             
             km = context.window_manager.keyconfigs.default.keymaps['Image Paint']
             #to do
@@ -872,9 +854,9 @@ class RemoveBProjectionPlane(Operator):
                     km.keymap_items.remove(kmi)
             
             tmp = context.object
-            '''for ob in (ob for ob in bpy.data.objects if ob.type == 'MESH' and ob.hide == False and context.scene in ob.users_scene):
+            for ob in (ob for ob in bpy.data.objects if ob.type == 'MESH' and ob.hide == False and context.scene in ob.users_scene):
                 context.scene.objects.active = ob
-                bpy.ops.object.mode_set(mode = 'OBJECT', toggle=False) '''
+                bpy.ops.object.mode_set(mode = 'OBJECT', toggle=False) 
             
             context.scene.objects.active = tmp
             ob = context.object           
@@ -1308,4 +1290,4 @@ def unregister():
     bpy.utils.unregister_module(__name__)
 
 if __name__ == "__main__":
-    register()
+    register()
\ No newline at end of file