[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4005] contrib/py/scripts/addons/ space_view3d_paint_bprojection.py: better fix for load factory and New file , use the handler
geo kgeo
kgeogeo at hotmail.com
Mon Nov 26 01:59:18 CET 2012
Revision: 4005
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4005
Author: kgeogeo
Date: 2012-11-26 00:59:17 +0000 (Mon, 26 Nov 2012)
Log Message:
-----------
better fix for load factory and New file, use the handler
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-11-26 00:10:37 UTC (rev 4004)
+++ contrib/py/scripts/addons/space_view3d_paint_bprojection.py 2012-11-26 00:59:17 UTC (rev 4005)
@@ -9,6 +9,7 @@
"category": "Paint"}
import bpy
+from bpy.app.handlers import persistent
from bpy.types import Panel, Operator
from bpy.props import IntProperty, FloatProperty, BoolProperty, IntVectorProperty, StringProperty, FloatVectorProperty, CollectionProperty
from bpy_extras import view3d_utils
@@ -1223,19 +1224,15 @@
return{'FINISHED'}
def invoke(self, context, event):
- try:
- bpy.data.objects['Empty for BProjection']
- context.window_manager.modal_handler_add(self)
- self.first_mouse = Vector((event.mouse_region_x,event.mouse_region_y))
- self.first_time = True
- for sub in context.object.modifiers:
- if sub.type in ['SUBSURF', 'MULTIRES']:
- self.tmp_level = sub.levels
- sub.levels = 0
- return {'RUNNING_MODAL'}
- except:
- reinitkey()
- return {'RUNNING_MODAL'}
+ bpy.data.objects['Empty for BProjection']
+ context.window_manager.modal_handler_add(self)
+ self.first_mouse = Vector((event.mouse_region_x,event.mouse_region_y))
+ self.first_time = True
+ for sub in context.object.modifiers:
+ if sub.type in ['SUBSURF', 'MULTIRES']:
+ self.tmp_level = sub.levels
+ sub.levels = 0
+ return {'RUNNING_MODAL'}
# Oprerator Class to pan the view3D
@@ -1284,20 +1281,17 @@
return {'RUNNING_MODAL'}
def invoke(self, context, event):
- try:
- bpy.data.objects['Empty for BProjection']
- context.window_manager.modal_handler_add(self)
- self.first_mouse.x = event.mouse_region_x
- self.first_mouse.y = event.mouse_region_y
- for sub in context.object.modifiers:
- if sub.type in ['SUBSURF', 'MULTIRES']:
- self.tmp_level = sub.levels
- sub.levels = 0
-
- return {'RUNNING_MODAL'}
- except:
- reinitkey()
- return {'RUNNING_MODAL'}
+ bpy.data.objects['Empty for BProjection']
+ context.window_manager.modal_handler_add(self)
+ self.first_mouse.x = event.mouse_region_x
+ self.first_mouse.y = event.mouse_region_y
+ for sub in context.object.modifiers:
+ if sub.type in ['SUBSURF', 'MULTIRES']:
+ self.tmp_level = sub.levels
+ sub.levels = 0
+
+ return {'RUNNING_MODAL'}
+
def execute(self, context):
align_to_view(context)
@@ -1315,47 +1309,43 @@
default=1.0)
def invoke(self, context, event):
- try:
- ob = context.object
- em = bpy.data.objects[BProjection_Empty]
- sd = context.space_data
-
- width = context.area.regions[4].width
- height = context.area.regions[4].height
-
- r3d = sd.region_3d
- v_init = Vector((0.0,0.0,1.0))
-
- pos = [width,height]
- vtr_b = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
- pos = [0,0]
- vbl_b = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
- len_b = vtr_b - vbl_b
-
- bpy.ops.view3d.zoom(delta = self.delta)
- r3d.update()
-
- pos = [width,height]
- vtr_a = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
- pos = [0,0]
- vbl_a = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
- len_a = vtr_a - vbl_a
-
- fac = len_a.length/len_b.length
- r3d.view_location -= ob.location
- r3d.view_location *= fac
- r3d.view_location += ob.location
- vres = Vector((em.custom_location.x*fac,em.custom_location.y*fac,em.custom_location.z))
- em.custom_location = vres
-
-
- align_to_view(context)
-
- return {'FINISHED'}
- except:
- reinitkey()
- return {'RUNNING_MODAL'}
+ ob = context.object
+ em = bpy.data.objects[BProjection_Empty]
+ sd = context.space_data
+ width = context.area.regions[4].width
+ height = context.area.regions[4].height
+
+ r3d = sd.region_3d
+ v_init = Vector((0.0,0.0,1.0))
+
+ pos = [width,height]
+ vtr_b = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
+ pos = [0,0]
+ vbl_b = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
+ len_b = vtr_b - vbl_b
+
+ bpy.ops.view3d.zoom(delta = self.delta)
+ r3d.update()
+
+ pos = [width,height]
+ vtr_a = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
+ pos = [0,0]
+ vbl_a = view3d_utils.region_2d_to_location_3d(context.region, r3d, pos, v_init)
+ len_a = vtr_a - vbl_a
+
+ fac = len_a.length/len_b.length
+ r3d.view_location -= ob.location
+ r3d.view_location *= fac
+ r3d.view_location += ob.location
+ vres = Vector((em.custom_location.x*fac,em.custom_location.y*fac,em.custom_location.z))
+ em.custom_location = vres
+
+
+ align_to_view(context)
+
+ return {'FINISHED'}
+
def execute(self, context):
align_to_view(context)
@@ -1368,35 +1358,36 @@
view = StringProperty(name="View", description="Select the view", default='TOP')
def invoke(self, context, event):
- try:
- ob = context.object
- em = bpy.data.objects[BProjection_Empty]
- origine = ob.location
- sd = context.space_data
-
- vr_b = sd.region_3d.view_rotation.copy()
- vr_b.invert()
- pos_init = sd.region_3d.view_location - origine
- sd.region_3d.view_location = origine
-
- tmp = context.user_preferences.view.smooth_view
- context.user_preferences.view.smooth_view = 0
- bpy.ops.view3d.viewnumpad(type=self.view)
- align_to_view(context)
- context.user_preferences.view.smooth_view = tmp
-
- vr_a = sd.region_3d.view_rotation.copy()
- pos_init.rotate(vr_a*vr_b)
- sd.region_3d.view_location = pos_init + origine
-
- return {'FINISHED'}
- except:
- reinitkey()
- return {'RUNNING_MODAL'}
+ ob = context.object
+ em = bpy.data.objects[BProjection_Empty]
+ origine = ob.location
+ sd = context.space_data
+ vr_b = sd.region_3d.view_rotation.copy()
+ vr_b.invert()
+ pos_init = sd.region_3d.view_location - origine
+ sd.region_3d.view_location = origine
+
+ tmp = context.user_preferences.view.smooth_view
+ context.user_preferences.view.smooth_view = 0
+ bpy.ops.view3d.viewnumpad(type=self.view)
+ align_to_view(context)
+ context.user_preferences.view.smooth_view = tmp
+
+ vr_a = sd.region_3d.view_rotation.copy()
+ pos_init.rotate(vr_a*vr_b)
+ sd.region_3d.view_location = pos_init + origine
+
+ return {'FINISHED'}
+
+ at persistent
+def load_handler(dummy):
+ reinitkey()
+
def register():
bpy.utils.register_module(__name__)
createcustomprops(bpy.context)
+ bpy.app.handlers.load_post.append(load_handler)
def unregister():
bpy.utils.unregister_module(__name__)
More information about the Bf-extensions-cvs
mailing list