problem with while loop

I am writing my first Python script. For a selected armature, it copies the current action and creates a mirrored copy (flipping all poses Left to right and right to left.

Here is the code:

import bpy

Last_Frame = -1
Current_Frame = bpy.context.scene.frame_current #get current frame number
Original_Action = bpy.context.object.animation_data.action  #get name of active action in active object/armature
Mirror_Action_Name = + '.mirror'  #create a new name for action, which will be mirrored
Mirror_Action = Original_Action.copy()  #create a copy action, which will be mirrored = Mirror_Action_Name   #name the new action
bpy.context.object.animation_data.action = Mirror_Action  #set the new action as the active action for the object/armature

while Last_Frame != Current_Frame:  #iterate through all the frames in the current action
    Last_Frame = Current_Frame;  #update Last_Frame  
    bpy.ops.pose.copy()  #copy  pose
    bpy.ops.pose.paste(flipped=True)  #mirror pose
    bpy.ops.anim.keyframe_insert(type='Available')  #insert keyframes for mirrored pose
    bpy.ops.screen.keyframe_jump(next=True)   # jump to next keyframe
    Current_Frame = bpy.context.scene.frame_current;print('current frame', Current_Frame) #update Current_Frame

Without the while loop, if I type things in line by line in the console, repeating everything in the while loop manually, it works fine. But when I add the while loop, only the first two keyframes change. Anyone willing to give a hint what’s happening?

demo file attached

This seems to produce the same result as if I do the actions in viewport:

import bpy

scene = bpy.context.scene
ob = bpy.context.object
action_orig = ob.animation_data.action

action_copy = action_orig.copy() = + ".mirror"
ob.animation_data.action = action_copy

while True:

    if bpy.ops.screen.keyframe_jump(next=True) != {'FINISHED'}:

Well – it’s nice to know how to check for the error flag, but I still have the same result. After exectuing the script, he goes from left leaning Y pose to right leaning Y pose, then back again.

Does Python/BPY have a puase function – i.e.


when it calls pause() it waits for user input (a keypress or mouseclick, etc)? Is there such a funtion so I could step through?