[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [743] contrib/py/scripts/addons/ space_view3d_copy_attributes.py: addons/space_view3d_copy_attributes. py moved to contrib.
Brendon Murphy
meta.androcto1 at gmail.com
Sun Jun 20 02:40:36 CEST 2010
Revision: 743
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=743
Author: meta-androcto
Date: 2010-06-20 02:40:35 +0200 (Sun, 20 Jun 2010)
Log Message:
-----------
addons/space_view3d_copy_attributes.py moved to contrib.
Added Paths:
-----------
contrib/py/scripts/addons/space_view3d_copy_attributes.py
Added: contrib/py/scripts/addons/space_view3d_copy_attributes.py
===================================================================
--- contrib/py/scripts/addons/space_view3d_copy_attributes.py (rev 0)
+++ contrib/py/scripts/addons/space_view3d_copy_attributes.py 2010-06-20 00:40:35 UTC (rev 743)
@@ -0,0 +1,303 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+bl_addon_info = {
+ 'name': '3D View: Copy Attributes Menu',
+ 'author': 'Bassam Kurdali',
+ 'version': '0.32 19-6-2010',
+ 'blender': (2, 5, 3),
+ 'location': 'View3D > Ctrl/C',
+ 'description': 'Copy Attributes Menu from Blender 2.4',
+ 'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3D_interaction/Copy_Attributes_Menu',
+ 'tracker_url': 'https://projects.blender.org/tracker/index.php?func=detail&aid=22588&group_id=153&atid=467',
+ 'category': '3D View'}
+
+__bpydoc__ = """
+Copy Menu
+
+
+"""
+import bpy, mathutils
+from mathutils import *
+
+def build_exec(loopfunc,func):
+ '''Generator function that returns exec functions for various operators '''
+ def exec_func(self, context):
+ loopfunc(self,context,func)
+ return {'FINISHED'}
+ return exec_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])
+ 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, 'poll', poll_func)
+ #print(op[0],op[3])
+ oplist.append(opclass)
+
+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))
+ except:
+ pass
+ return
+
+def getmat( bone , active , context , ignoreparent ):
+ '''Helper function for visual transform copy, gets the active transform in bone space'''
+ #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)
+ else:
+ parentposemat = bonemat_local.copy().identity()
+ parentbonemat = bonemat_local.copy().identity()
+ if parentbonemat == parentposemat or ignoreparent:
+ newmat = bonemat_local.invert() * otherloc
+ else:
+ bonemat = parentbonemat.invert() * bonemat_local
+
+ newmat = bonemat.invert() * parentposemat.invert() * otherloc
+ return newmat
+
+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])
+ 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)
+
+#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 pLocScaExec(bone, active, context): bone.scale = active.scale
+
+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].hinge ))
+
+def pVisScaExec(bone, active, context): bone.scale = getmat(bone,active,context , not context.active_object.data.bones[bone.name].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
+ for index, state in enumerate(active.lock_rotation):
+ bone.lock_rotation[index] = state
+ for index, state in enumerate(active.lock_rotations_4d):
+ bone.lock_rotations_4d[index] = state
+ bone.lock_rotation_w = active.lock_rotation_w
+ 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)
+
+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))
+
+def pose_poll_func(self, context):
+ return(context.mode == 'POSE')
+
+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"
+
+ def draw(self, context):
+ 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")
+
+def obLoopExec(self, context, funk):
+ '''Loop over selected objects and execute funk on them'''
+ active = context.active_object
+ selected = context.selected_objects[:]
+ selected.remove(active)
+ for obj in selected:
+ funk(obj, active,context)
+
+#The following functions are used o copy attributes frome active to selected object
+
+def obLoc (ob, active, context): ob.location = active.location
+
+def obRot (ob, active, context): rotcopy(ob, active.matrix.rotation_part())
+
+def obSca (ob, active, context): ob.scale = active.scale
+
+def obDrw (ob, active, context):
+ ob.max_draw_type = active.max_draw_type
+ ob.draw_axis = active.draw_axis
+ ob.draw_bounds = active.draw_bounds
+ ob.draw_bounds_type = active.draw_bounds_type
+ ob.draw_name = active.draw_name
+ ob.draw_texture_space = active.draw_texture_space
+ ob.draw_transparent = active.draw_transparent
+ ob.draw_wire = active.draw_wire
+ ob.empty_draw_type = active.empty_draw_type
+ ob.empty_draw_size = active.empty_draw_size
+
+def obOfs (ob, active, context): ob.time_offset = active.time_offset
+
+def obDup (ob, active, context): generic_copy(active,ob,"dupli")
+
+def obCol (ob, active, context): ob.color = active.color
+
+def obLok (ob, active, context):
+ for index, state in enumerate(active.lock_location):
+ ob.lock_location[index] = state
+ for index, state in enumerate(active.lock_rotation):
+ ob.lock_rotation[index] = state
+ for index, state in enumerate(active.lock_rotations_4d):
+ ob.lock_rotations_4d[index] = state
+ ob.lock_rotation_w = active.lock_rotation_w
+ for index, state in enumerate(active.lock_scale):
+ ob.lock_scale[index] = state
+
+def obCon (ob, active, context):
+ #for consistency with 2.49, delete old constraints first
+ for index in range(len(ob.constraints.values())-1,-1,-1):
+ ob.constraints.remove(index)
+ for old_constraint in active.constraints.values():
+ new_constraint = ob.constraints.new(old_constraint.type)
+ generic_copy(old_constraint,new_constraint)
+
+def obTex (ob, active, context):
+ if 'texspace_loc' in dir(ob.data) and 'texspace_loc' in dir(active.data):
+ ob.data.texspace_loc = active.data.texspace_loc
+ if 'texspace_size' in dir(ob.data) and 'texspace_size' in dir(active.data):
+ ob.data.texspace_size = active.data.texspace_size
+
+def obIdx (ob, active, context): ob.pass_index = active.pass_index
+
+def obMod (ob, active, context):
+ for modifier in ob.modifiers.values():
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list