Bake Keyframes selected bone This is how I do it in maya

refresh -su true;
    string $startFrame = `playbackOptions -q -min`;
    string $endFrame = `playbackOptions -q -max`;
    bakeResults -t (($startFrame) + ":" + ($endFrame)) -sm true -sr false -sb 1.0 -pok true -dl "bakedTRANS";
    refresh -su false;


Wonder if someone can do it in blender. I want to select a bone and bake the selected range that I assign in the viewport exp frame 0 to 30 and he bakes that range but if I change the range he would bake 0-40f
--bpy.ops.nla.bake(frame_start = context.scene.frame_start, frame_end = context.scene.frame_end, visual_keying=True, bake_types={'OBJECT'})--

which means you bake all your frames using an NLA editor.