Matching bone positions regardless of constraints

I’ve been trying to find a solution to a rigging problem I have.

I have kind of a faux IK/FK setup for the arms of a character.
I have two Child Of constraints for the hand IK control. One is a child of the chest, the other a child of the master for the character, and I have them inversely linked via a driver (Meaning when one Child Of constraint is 1, the other is 0, and vice versa).

The effect is this: When the IK control is influenced by the master, the control behaves as you’d expect an IK control to behave. However, when the IK control is influenced by the chest, it still retains the IK behavior, but also moves parented to the chest like FK. Best of both worlds for my needs.

Demo:

As you can see, the problem happens when I’m dialing the influence from one constraint to the other. Namely, the control shifts if the chest control has been altered.

Here’s my question: What can I do to match one position to the other after dialing the influence slider?

I’ve tried one method copying visual transformation using the “Copy Attributes” addon, but has its own problem.

So I’m trying another method through an extraction/modification of code from the Dynamic Parent addon. The following is what I have:

import bpy
import mathutils


def dp_keyframe_insert_pbone(arm, pbone):
    arm.keyframe_insert(data_path='pose.bones["'+pbone.name+'"].location')
    if pbone.rotation_mode == 'QUATERNION':
        arm.keyframe_insert(data_path='pose.bones["'+pbone.name+'"].rotation_quaternion')
    elif pbone.rotation_mode == 'AXIS_ANGLE':
        arm.keyframe_insert(data_path='pose.bones["'+pbone.name+'"].rotation_axis_angel')
    else:
        arm.keyframe_insert(data_path='pose.bones["'+pbone.name+'"].rotation_euler')
    arm.keyframe_insert(data_path='pose.bones["'+pbone.name+'"].scale') 
    
arm = bpy.context.active_object
pbone = bpy.context.active_pose_bone
scn = bpy.context.scene


current_frame = scn.frame_current
scn.frame_current = current_frame - 1
pbone.constraints["Torso"].influence = 1
arm.keyframe_insert(data_path='pose.bones["'+pbone.name+'"].constraints["Torso"].influence')
        
scn.frame_current = current_frame
pbone.constraints["Torso"].influence = 0
arm.keyframe_insert(data_path='pose.bones["'+pbone.name+'"].constraints["Torso"].influence')
        
final_matrix = pbone.matrix
        
current_frame = scn.frame_current
scn.frame_current = current_frame - 1
dp_keyframe_insert_pbone(arm, pbone)
        
scn.frame_current = current_frame
pbone.matrix = final_matrix
dp_keyframe_insert_pbone(arm, pbone)

But it only works when the “Torso” Child Of constraint is at the influence of “1”; it doesn’t work when I run the script with the influence at “0” (And changing the first “pbone.constraints[“Torso”].influence =” to 0, and second to 1).

I’m guessing scripting is going to have to end up being the solution, but not sure how to make this work.
Blend file attached. Any help would be much appreciated!

Attachments

IKparentChange_withScript.blend (5.36 MB)