[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1030] contrib/py/scripts/addons/ space_view3d_copy_attributes.py: pep8 compliant

bassam kurdali bkurdali at freefactory.org
Sun Sep 12 19:40:54 CEST 2010


Revision: 1030
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1030
Author:   bassamk
Date:     2010-09-12 19:40:54 +0200 (Sun, 12 Sep 2010)

Log Message:
-----------
pep8 compliant

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

Modified: contrib/py/scripts/addons/space_view3d_copy_attributes.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_copy_attributes.py	2010-09-12 12:48:35 UTC (rev 1029)
+++ contrib/py/scripts/addons/space_view3d_copy_attributes.py	2010-09-12 17:40:54 UTC (rev 1030)
@@ -16,10 +16,12 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
+# <pep8 compliant>
+
 bl_addon_info = {
     'name': 'Copy Attributes Menu',
     'author': 'Bassam Kurdali, Fabian Fricke',
-    'version': (0,36),
+    'version': (0, 36),
     'blender': (2, 5, 4),
     'api': 31881,
     'location': 'View3D > Ctrl/C',
@@ -35,53 +37,66 @@
 
 
 """
-import bpy, mathutils
+import bpy
+import mathutils
 from mathutils import *
 
-def build_exec(loopfunc,func):
-    '''Generator function that returns exec functions for various operators '''
+
+def build_exec(loopfunc, func):
+    '''Generator function that returns exec functions for operators '''
+
     def exec_func(self, context):
-        loopfunc(self,context,func)
+        loopfunc(self, context, func)
         return {'FINISHED'}
     return exec_func
 
-def build_invoke(loopfunc,func):
-    '''Generator function that returns invoke functions for various operators'''
+
+def build_invoke(loopfunc, func):
+    '''Generator function that returns invoke functions for operators'''
+
     def invoke_func(self, context, event):
         loopfunc(self, context, func)
         return {'FINISHED'}
     return invoke_func
 
+
 def genops(copylist, oplist, prefix, poll_func, loopfunc):
     '''Generate ops from the copy list and its associated functions '''
     for op in copylist:
-        exec_func = build_exec(loopfunc,op[3])
-        invoke_func = build_invoke(loopfunc,op[3])
-        opclass = type(op[0], (bpy.types.Operator,), dict(bl_idname=prefix+op[0], bl_label="Copy " +op[1], bl_description = op[2]))
+        exec_func = build_exec(loopfunc, op[3])
+        invoke_func = build_invoke(loopfunc, op[3])
+        opclass = type(op[0], (bpy.types.Operator,),
+           dict(bl_idname=prefix + op[0],
+           bl_label="Copy " + op[1], bl_description=op[2]))
         setattr(opclass, 'execute', exec_func)
         setattr(opclass, 'invoke', invoke_func)
         setattr(opclass, 'poll', poll_func)
-        #print(op[0],op[3])
         oplist.append(opclass)
 
-def generic_copy(source,target,string=""):
+
+def generic_copy(source, target, string=""):
     ''' copy attributes from source to target that have string in them '''
     for attr in dir(source):
         if attr.find(string) > -1:
             try:
-                setattr(target,attr,getattr(source,attr))
+                setattr(target, attr, getattr(source, attr))
             except:
                 pass
     return
 
-def getmat( bone , active , context , ignoreparent ):
-    '''Helper function for visual transform copy, gets the active transform in bone space'''
+
+def getmat(bone, active, context, ignoreparent):
+    '''Helper function for visual transform copy,
+       gets the active transform in bone space
+    '''
+    data_bone = context.active_object.data.bones[bone.name]
     #all matrices are in armature space unless commented otherwise
     otherloc = active.matrix #final 4x4 mat of target, location.
-    bonemat_local = Matrix( context.active_object.data.bones[bone.name].matrix_local) #self rest matrix
-    if context.active_object.data.bones[bone.name].parent:
-        parentposemat = Matrix(context.active_object.pose.bones[context.active_object.data.bones[bone.name].parent.name].matrix)
-        parentbonemat = Matrix(context.active_object.data.bones[bone.name].parent.matrix_local)
+    bonemat_local = Matrix(data_bone.matrix_local) #self rest matrix
+    if data_bone.parent:
+        parentposemat = Matrix(
+           context.active_object.pose.bones[data_bone.parent.name].matrix)
+        parentbonemat = Matrix(data_bone.parent.matrix_local)
     else:
         parentposemat = bonemat_local.copy().identity()
         parentbonemat = bonemat_local.copy().identity()
@@ -90,43 +105,64 @@
     else:
         bonemat = parentbonemat.invert() * bonemat_local
 
-        newmat =  bonemat.invert() * parentposemat.invert()  * otherloc
+        newmat = bonemat.invert() * parentposemat.invert() * otherloc
     return newmat
 
-def rotcopy(item,mat):
+
+def rotcopy(item, mat):
     '''copy rotation to item from matrix mat depending on item.rotation_mode'''
     if item.rotation_mode == 'QUATERNION':
         item.rotation_quaternion = mat.rotation_part().to_quat()
     elif item.rotation_mode == 'AXIS_ANGLE':
         quat = mat.rotation_part().to_quat()
-        item.rotation_axis_angle = Vector([quat.axis[0],quat.axis[1],quat.axis[2],quat.angle])
+        item.rotation_axis_angle = Vector([quat.axis[0],
+           quat.axis[1], quat.axis[2], quat.angle])
     else:
         item.rotation_euler = mat.rotation_part().to_euler(item.rotation_mode)
 
+
 def pLoopExec(self, context, funk):
     '''Loop over selected bones and execute funk on them'''
     active = context.active_pose_bone
     selected = context.selected_pose_bones
     selected.remove(active)
     for bone in selected:
-        funk(bone, active,context)
+        funk(bone, active, context)
 
 #The following functions are used o copy attributes frome active to bone
 
-def pLocLocExec (bone, active, context): bone.location = active.location
 
-def pLocRotExec (bone, active, context): rotcopy(bone, active.matrix_local.rotation_part())
+def pLocLocExec(bone, active, context):
+    bone.location = active.location
 
-def pLocScaExec(bone, active, context): bone.scale = active.scale
 
-def pVisLocExec(bone, active, context): bone.location = getmat(bone,active,context,False).translation_part()
+def pLocRotExec(bone, active, context):
+    rotcopy(bone, active.matrix_local.rotation_part())
 
-def pVisRotExec(bone, active, context): rotcopy(bone,  getmat(bone,active,context,not context.active_object.data.bones[bone.name].use_hinge ))
 
-def pVisScaExec(bone, active, context): bone.scale = getmat(bone,active,context , not context.active_object.data.bones[bone.name].use_inherit_scale ).scale_part()
+def pLocScaExec(bone, active, context):
+    bone.scale = active.scale
 
-def pDrwExec(bone, active, context): bone.custom_shape = active.custom_shape
 
+def pVisLocExec(bone, active, context):
+    bone.location = getmat(bone, active, context, False).translation_part()
+
+
+def pVisRotExec(bone, active, context):
+    rotcopy(bone, getmat(bone, active,
+      context, not context.active_object.data.bones[bone.name].use_hinge))
+
+
+def pVisScaExec(bone, active, context):
+    bone.scale = getmat(bone, active, context,
+       not context.active_object.data.bones[bone.name].use_inherit_scale)\
+          .scale_part()
+
+
+def pDrwExec(bone, active, context):
+    bone.custom_shape = active.custom_shape
+
+
 def pLokExec(bone, active, context):
     for index, state in enumerate(active.lock_location):
         bone.lock_location[index] = state
@@ -138,33 +174,47 @@
     for index, state in enumerate(active.lock_scale):
         bone.lock_scale[index] = state
 
+
 def pConExec(bone, active, context):
     for old_constraint in  active.constraints.values():
         new_constraint = bone.constraints.new(old_constraint.type)
-        generic_copy(old_constraint,new_constraint)
+        generic_copy(old_constraint, new_constraint)
 
-def pIKsExec(bone, active, context): generic_copy(active,bone,"ik_")
 
+def pIKsExec(bone, active, context):
+    generic_copy(active, bone, "ik_")
 
-pose_copies =  (('POSE_LOC_LOC', "Local Location", "Copy Location from Active to Selected",pLocLocExec),
-                ('POSE_LOC_ROT', "Local Rotation", "Copy Rotation from Active to Selected",pLocRotExec),
-                ('POSE_LOC_SCA', "Local Scale", "Copy Scale from Active to Selected",pLocScaExec),
-                ('POSE_VIS_LOC', "Visual Location", "Copy Location from Active to Selected",pVisLocExec),
-                ('POSE_VIS_ROT', "Visual Rotation", "Copy Rotation from Active to Selected",pVisRotExec),
-                ('POSE_VIS_SCA', "Visual Scale", "Copy Scale from Active to Selected",pVisScaExec),
-                ('POSE_DRW', "Bone Shape", "Copy Bone Shape from Active to Selected",pDrwExec),
-                ('POSE_LOK', "Protected Transform", "Copy Protected Tranforms from Active to Selected",pLokExec),
-                ('POSE_CON', "Object Constraints", "Copy Object Constraints from Active to Selected",pConExec),
-                ('POSE_IKS', "IK Limits","Copy IK Limits from Active to Selected",pIKsExec))
+pose_copies = (('POSE_LOC_LOC', "Local Location",
+                "Copy Location from Active to Selected", pLocLocExec),
+                ('POSE_LOC_ROT', "Local Rotation",
+                "Copy Rotation from Active to Selected", pLocRotExec),
+                ('POSE_LOC_SCA', "Local Scale",
+                "Copy Scale from Active to Selected", pLocScaExec),
+                ('POSE_VIS_LOC', "Visual Location",
+                "Copy Location from Active to Selected", pVisLocExec),
+                ('POSE_VIS_ROT', "Visual Rotation",
+                "Copy Rotation from Active to Selected", pVisRotExec),
+                ('POSE_VIS_SCA', "Visual Scale",
+                "Copy Scale from Active to Selected", pVisScaExec),
+                ('POSE_DRW', "Bone Shape",
+                "Copy Bone Shape from Active to Selected", pDrwExec),
+                ('POSE_LOK', "Protected Transform",
+                "Copy Protected Tranforms from Active to Selected", pLokExec),
+                ('POSE_CON', "Object Constraints",
+                "Copy Object Constraints from Active to Selected", pConExec),
+                ('POSE_IKS', "IK Limits",
+                "Copy IK Limits from Active to Selected", pIKsExec))
 
+
 @classmethod
 def pose_poll_func(cls, context):
     return(context.mode == 'POSE')
 
-pose_ops=[] #list of pose mode copy operators
+pose_ops = [] #list of pose mode copy operators
 
 genops(pose_copies, pose_ops, "pose.copy_", pose_poll_func, pLoopExec)
 
+
 class VIEW3D_MT_posecopypopup(bpy.types.Menu):
     bl_label = "Copy Attributes"
 
@@ -172,28 +222,37 @@
         layout = self.layout
         layout.operator_context = 'INVOKE_REGION_WIN'
         for op in pose_copies:
-            layout.operator("pose.copy_"+op[0])
-        layout.operator("pose.copy",text="copy pose")

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list