LapisSea

Untitled

Oct 12th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. import bpy
  2. import math
  3. import time
  4.  
  5. context = bpy.context
  6. scene = context.scene
  7. MyArmature = bpy.data.objects["Armature"]
  8.  
  9. all_bones = bpy.context.selected_pose_bones
  10.  
  11. current_milli_time = lambda: int(round(time.time() * 1000))
  12.  
  13. def _mirrorConstraints(bone,fr,to):
  14.     boneL = MyArmature.data.bones[bone.name]
  15.     if boneL is None:
  16.         return
  17.     boneR = MyArmature.data.bones[bone.name.replace(fr,to)]
  18.     if boneR is None:
  19.         return
  20.    
  21.     boneR.select = True
  22.     boneL.select = True
  23.     boneR.bbone_x=boneL.bbone_x
  24.     boneR.bbone_z=boneL.bbone_z
  25.    
  26.     if len(MyArmature.pose.bones[boneL.name].constraints) !=0:
  27.        
  28.         MyArmature.data.bones.active = boneL
  29.         bpy.ops.object.constraints_copy()
  30.         bpy.ops.pose.constraints_copy()
  31.        
  32.         for con in MyArmature.pose.bones[boneR.name].constraints:
  33.             try:
  34.                 con.subtarget = con.subtarget.replace(fr,to)
  35.             except AttributeError:
  36.                 print('')
  37.             if con.name=='IK':
  38.                 con.pole_subtarget=con.pole_subtarget.replace(fr,to)
  39.                 _mirrorIKPole(con)
  40.                
  41. def mirrorConstraints():
  42.     i=0.0
  43.     tim=current_milli_time()
  44.     for bone in all_bones:
  45.         i+=1
  46.         t=current_milli_time()
  47.         if tim<t:
  48.             tim=t+1000;
  49.             print(str(round((i*100)/len(all_bones),2))+"%")
  50.        
  51.         bpy.ops.pose.select_all(action='DESELECT')
  52.         if ".L" in bone.name:
  53.             _mirrorConstraints(bone,'.L','.R');
  54.         if ".R" in bone.name:
  55.             _mirrorConstraints(bone,'.R','.L');
  56.    
  57.     bpy.ops.pose.select_all(action='DESELECT')
  58.     for bone in all_bones:
  59.         MyArmature.data.bones[bone.name].select = True
  60.        
  61. def _mirrorIKPole(con):
  62.     pol=con.pole_angle
  63.     pol-=math.pi
  64.     if pol < -math.pi:
  65.         pol+=math.pi*2
  66.     con.pole_angle=pol
  67.    
  68. def mirrorIKPole():
  69.     for bone in all_bones:
  70.            
  71.         for con in bone.constraints:
  72.             if con.name=='IK':
  73.                 _mirrorIKPole(con)
  74.  
  75. # too lazy learn how to register this functions to UI buttons xD               
  76. # mirrorConstraints()
  77. # mirrorIKPole()
Add Comment
Please, Sign In to add comment