Why isn't my script inverting all poses from all keyframes?

I hope I can find some help:

the code works great placing all poses at same position but for some reason it doesn’t paste flipped. Any ideas?

import bpy
import math


ctx = bpy.context
ops = bpy.ops
obj = ctx.object


ctx.scene.frame_start = 0
ctx.scene.frame_end = 1229
ctx.scene.frame_current = 0


for i in range(400):
    ctx.scene.frame_current = i
    obj.location.x = 0
    obj.location.y = 0
    ops.pose.loc_clear()
    ops.pose.copy()
    ops.pose.paste(flipped=True)
    ops.anim.keyframe_insert_menu(type='LocRotScale')

I couldn’t figure this out yet, I’ve reserched a lot and nothing.

I’m starting to think it is a blender issue, is it?

the bpy.ops commands usually require a window context (not all but most), rather then running it via a script…

is this for a rig or is this for objects?

Hello,

don’t have an answer for you
if I’m not mistaken flipping animations only works on armature bones

although

This script flips animations

It could be useful to read.

rigging, I run this on the desired bones in pose mode, thanks