replacing property rna path of disabled fcurves

the challenge is as follows. I’d like to re-use animation from one armature on another, however the bone names are different for naming convention and other reasons. The simple (and time consuming) solutions are:

  1. copy the new bone names and replace the names in the rna path. e.g. pose.bones[“Hand L”].location becomes pose.bones[“hand.IK.l”].location
  2. copy the rna paths from the properties window and paste them into the graph editor properties panel.

while hitting ctrl c ctrl v for an hour i thought that maybe the steps from 1) could be done by a script, take the currently in the 3d view selected bone’s name and replace the parts in parenthesis of the property rna paths (“bonename”) of all currently selected fcurves with that.
With this it would be a matter of selecting the bone, selecting the fcurves and hitting a button to get all channels working on that bone.
Ideally there would be a button in the tool panel or somewhere in the graph editor for it.

Problem is that i have very limited knowledge on bpy scripting and it would take me some weeks to figure something out, so ideas and pointers on how to do this would be neat.

there is an Motion Capturing addon, which has a Retarget feature. But it seems to add a keyframe for every frame… need to check on the options.

Ok, I wrote a little script, maybe this is more useful:

import bpy

replace = {
"foo": "something",
"bar": "Bone.001"

ob = bpy.context.object

for c in ob.animation_data.action.fcurves:
    p = c.data_path
    name = p[p.find('["')+2:p.rfind('"]')]
    target_name = replace.get(name)
    if target_name:
        print("Replacing %s by %s" % (name, target_name))
        c.data_path = p.replace('["' + name + '"]', '["' + target_name + '"]')

you set up a mapping at the top, like

'current_datapath_name': 'actual_bone_name',

then run the script and it will change the datapaths.

This could be nicely done with UI of course, but do you really need that?

An automated retargeting can be difficult, just walking over the selected fcurves and bones wouldn’t work, as the order is determined by names (alphabetical order). Not sure how to walk over them correctly…