Inserting key on every frame not working

can you take a look at the script and try to fix it? it’s only 7 lines. Any alternatives would be helpful too.
my script is supposed to be a macro-ish script that :

  1. takes in curve data in the graph editor
  2. inserts a keyframe on every frame.and keeps the curves somewhat intact

I thought it would be easy as just iterating though each frame and doing a bpy.ops.anim.keyframe_insert(), but it’s inserting null/pointless keyframes and totally ignoring the data in the graph editor.

import bpy
# for each keyframe, insert key on the z 

counter = 0
for i in range(1,bpy.context.scene.frame_end):
    bpy.ops.anim.change_frame(frame = counter)
    counter = counter+ 1
    print("just on frame")
    print( int(bpy.context.scene.frame_current)) 

I’m trying to follow advice here under comment #3 : if you’re interested

anyways, if you can fix my script or come up with another way of putting in 1 key for every frame , that would be great. thanks in advance :yes:

if you really want a key on each frame you can do it from f-curves editor with Shift+O
works for a selected curve or just between selected keyframes…
wow, that was easy. thanks.