import bpy
def showHide(v, *args):
for arg in args:
bpy.data.armatures['Armature'].bones[arg].hide = v
def apply_transforms(*args):
for arg in args:
bone = bpy.context.object.pose.bones[arg].bone
bpy.context.object.data.bones.active = bone
bpy.ops.pose.visual_transform_apply()
def copyRot(conbone, contarget, influence=1, name=None, apply=True):
bon = bpy.context.object.pose.bones[conbone].bone
bpy.context.object.data.bones.active = bon
pbone = bpy.context.active_pose_bone
target = bpy.context.scene.objects.get("Armature")
subtarget = bpy.context.scene.objects.get("Armature").pose.bones.get(contarget)
constraint = pbone.constraints.new('COPY_ROTATION')
constraint.target = target
constraint.subtarget = subtarget.name
constraint.influence = influence
if name!=None:
constraint.name = name
if apply==True:
bpy.ops.constraint.apply(constraint=constraint.name, owner='BONE', report=False)
def copyLoc(conbone, contarget, headtail=0):
hand = bpy.context.object.pose.bones[conbone].bone
bpy.context.object.data.bones.active = hand
pbone = bpy.context.active_pose_bone
target = bpy.context.scene.objects.get("Armature")
subtarget = bpy.context.scene.objects.get("Armature").pose.bones.get(contarget)
constraint = pbone.constraints.new('COPY_LOCATION')
constraint.target = target
constraint.subtarget = subtarget.name
constraint.head_tail = headtail
bpy.ops.constraint.apply(constraint=constraint.name, owner='BONE', report=False)
switchMode = bpy.data.objects['Armature'].pose.bones['PROPERTIES']['ARM_L_IK/FK SWITCH']
Armedit = bpy.data.objects['Armature'].data
if switchMode == 0:
apply_transforms('upperArm_IKFK.L','foreArm_IKFK.L','hand_IKFK.L',
'handRoll_0_arm.L','handRoll_1_arm.L','handRoll_IKhandle_2_arm.L',
'poleHandle_arm.L','handRoll_ROTATE.L')
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
Armedit.edit_bones['handRoll_0_arm.L'].parent = None
bpy.ops.object.mode_set(mode='POSE', toggle=False)
copyLoc('handRoll_0_arm.L', 'hand_IKFK.L')
copyRot('handRoll_0_arm.L', 'handRoll_ROTATE.L')
copyRot('poleHandle_arm.L', 'poleHandle_arm_ROTATE.L')
copyRot('vectorNorm_2_arm.L', 'vectorNorm_MATCH_arm.L', name='vecArmRot.L', apply=False)
bpy.data.objects['Armature'].pose.bones['vectorNorm_2_arm.L'].rotation_quaternion[0]=1
bpy.data.objects['Armature'].pose.bones['vectorNorm_2_arm.L'].rotation_quaternion[1]=0
bpy.data.objects['Armature'].pose.bones['vectorNorm_2_arm.L'].rotation_quaternion[2]=0
bpy.data.objects['Armature'].pose.bones['vectorNorm_2_arm.L'].rotation_quaternion[3]=0
bpy.data.objects['Armature'].pose.bones['PROPERTIES']['ARM_L_IK/FK SWITCH'] = float(1)
bpy.ops.constraint.apply(constraint='vecArmRot.L', owner='BONE', report=False)
elif switchMode == 1:
bpy.context.object.data.bones.active = bpy.data.objects['Armature'].pose.bones['clavicle.L'].bone
con = bpy.data.objects['Armature'].pose.bones['clavicle.L'].constraints['clav_ROT'].name
bpy.ops.constraint.apply(constraint=con, owner='BONE', report=False)
apply_transforms('upperArm_IKFK.L','foreArm_IKFK.L','hand_IKFK.L',
'handRoll_1_arm.L','handRoll_IKhandle_2_arm.L',
'poleHandle_arm.L','handRoll_ROTATE.L','clavicle.L','upperArm_IKhandle.L',
'autoClav_FOLLOW.L','autoClavicle.L','upperArm_ROTATE.L',
'upperArm_ROTATE_FOLLOW.L')
copyRot('autoClavicle.L', 'clavicle.L')
copyRot('clavicle.L', 'autoClavicle.L', influence=0.5, name='clav_ROT', apply=False)
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
Armedit.edit_bones['handRoll_0_arm.L'].parent = Armedit.edit_bones['hand_IKFK.L']
bpy.ops.object.mode_set(mode='POSE', toggle=False)
bpy.data.objects['Armature'].pose.bones['PROPERTIES']['ARM_L_IK/FK SWITCH'] = float(0)
bpy.data.objects['Armature'].pose.bones['handRoll_0_arm.L'].location[0]=0
bpy.data.objects['Armature'].pose.bones['handRoll_0_arm.L'].location[1]=0
bpy.data.objects['Armature'].pose.bones['handRoll_0_arm.L'].location[2]=0
bpy.data.objects['Armature'].pose.bones['handRoll_0_arm.L'].rotation_quaternion[0]=1
bpy.data.objects['Armature'].pose.bones['handRoll_0_arm.L'].rotation_quaternion[1]=0
bpy.data.objects['Armature'].pose.bones['handRoll_0_arm.L'].rotation_quaternion[2]=0
bpy.data.objects['Armature'].pose.bones['handRoll_0_arm.L'].rotation_quaternion[3]=0
bpy.data.objects['Armature'].pose.bones['vectorNorm_2_arm.L'].rotation_quaternion[0]=1
bpy.data.objects['Armature'].pose.bones['vectorNorm_2_arm.L'].rotation_quaternion[1]=0
bpy.data.objects['Armature'].pose.bones['vectorNorm_2_arm.L'].rotation_quaternion[2]=0
bpy.data.objects['Armature'].pose.bones['vectorNorm_2_arm.L'].rotation_quaternion[3]=0
copyLoc('handRoll_0_arm.L', 'handRoll_ROTATE.L')
copyRot('handRoll_0_arm.L', 'handRoll_ROTATE.L')
else:
pass