Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import math
- import time
- context = bpy.context
- scene = context.scene
- MyArmature = bpy.data.objects["Armature"]
- all_bones = bpy.context.selected_pose_bones
- current_milli_time = lambda: int(round(time.time() * 1000))
- def _mirrorConstraints(bone,fr,to):
- boneL = MyArmature.data.bones[bone.name]
- if boneL is None:
- return
- boneR = MyArmature.data.bones[bone.name.replace(fr,to)]
- if boneR is None:
- return
- boneR.select = True
- boneL.select = True
- boneR.bbone_x=boneL.bbone_x
- boneR.bbone_z=boneL.bbone_z
- if len(MyArmature.pose.bones[boneL.name].constraints) !=0:
- MyArmature.data.bones.active = boneL
- bpy.ops.object.constraints_copy()
- bpy.ops.pose.constraints_copy()
- for con in MyArmature.pose.bones[boneR.name].constraints:
- try:
- con.subtarget = con.subtarget.replace(fr,to)
- except AttributeError:
- print('')
- if con.name=='IK':
- con.pole_subtarget=con.pole_subtarget.replace(fr,to)
- _mirrorIKPole(con)
- def mirrorConstraints():
- i=0.0
- tim=current_milli_time()
- for bone in all_bones:
- i+=1
- t=current_milli_time()
- if tim<t:
- tim=t+1000;
- print(str(round((i*100)/len(all_bones),2))+"%")
- bpy.ops.pose.select_all(action='DESELECT')
- if ".L" in bone.name:
- _mirrorConstraints(bone,'.L','.R');
- if ".R" in bone.name:
- _mirrorConstraints(bone,'.R','.L');
- bpy.ops.pose.select_all(action='DESELECT')
- for bone in all_bones:
- MyArmature.data.bones[bone.name].select = True
- def _mirrorIKPole(con):
- pol=con.pole_angle
- pol-=math.pi
- if pol < -math.pi:
- pol+=math.pi*2
- con.pole_angle=pol
- def mirrorIKPole():
- for bone in all_bones:
- for con in bone.constraints:
- if con.name=='IK':
- _mirrorIKPole(con)
- # too lazy learn how to register this functions to UI buttons xD
- # mirrorConstraints()
- # mirrorIKPole()
Add Comment
Please, Sign In to add comment