Is there more efficient way to copy keyframes programmatically from mesh A shape key to the similar shape key in the mesh B?

Here's the approach I'm using but it's kind of slow (for 160 shape keys it works at speed 3 keyframes per second) and creates lots of unnecessary keyframes.

for kf_i in range(scene.frame_start, scene.frame_end+1):
    print(f'Current keyframe - #{kf_i}')
    for dest_sk_name in shape_keys_convertion:
        base_sk_name = shape_keys_convertion[dest_sk_name]
        base_sk = o.data.shape_keys.key_blocks[base_sk_name]
        dest_sk = d.data.shape_keys.key_blocks[dest_sk_name]
        dest_sk.value = base_sk.value
        dest_sk.keyframe_insert('value', frame=kf_i)
  • $\begingroup$ If you have one action on the base sk that you want to copy over to one new action on the dest sk, renaming keyblocks, there's a much faster way. Is that what you want? $\endgroup$
    – scurest
    Commented Nov 9, 2021 at 19:47
  • $\begingroup$ @scurest kind of $\endgroup$ Commented Nov 9, 2021 at 20:02
  • $\begingroup$ Well, it kind of matters. keyframe_insert is for inserting into existing fcurves. If you're making a new fcurve it's much faster to use foreach_set. And it's even faster to just copy an action and rename the keyblocks its fcurves target. $\endgroup$
    – scurest
    Commented Nov 9, 2021 at 20:06
  • $\begingroup$ Oh my god, I just spent so much time writing new version of my script that would create fcurves identical to the base action. I was not realizing that actions are not attached to the mesh and I could have just rename all shape keys and that would work. Thank you! PS Never heard of foreach_set method before know, it might actually save some time in the future, thanks. $\endgroup$ Commented Nov 9, 2021 at 20:44

1 Answer 1


Actually there is no need for some special script to transfer shape key animation from one mesh to another. Because animation is attached to the action but actions are not attached to some mesh - meaning you can just run the same action on the other mesh. Possibly you will need to rename some of shape keys but it will work.

  • $\begingroup$ As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. $\endgroup$
    – TheLabCat
    Commented Sep 21, 2022 at 4:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .