[Script]Nudge Keyframe

This has been on my mind whole week.

Recently I was testing something out, and somehow I got the feeling that I just wanted to tell the keyframes to fill in the space up to some particular spot in the timeline. And I had this idea come to me before, when I was animating more frequently.

And yes I guess you can do that with scale. But I found that way a bit to fiddly. And I wanted to make sure that if I have non selected keyframes after the selected, they are respected in the process. Unless there is a blender function that I don’t know of…this is what I made it do:

  1. Takes the distance between the first selected keyframe and the timeline marker.
  2. Calculates the proprtion/divisions in the distance, based on selected keyframes
  3. Generates new positions that euqally fills the space with the first keyframe not being affected(it’s the origin point) and the last keyframe being the timeline marker’s position.
  4. Looks up the initial distance between the last selected and the first non selected keyframe, and makes sure all non selected keyframes now have a new position where all of them will still retain that initial distance from the last selected.
  5. Assigns the new positions.

So I think, while it can be done with simple scaling of keyframes , it will still require few steps more than just a click of a button or a hotkey.

There is this slight issue though, and that is that finding the new position turns the result in to float, and greaspencil’s keyframes convert floats in to integers, thus a keyframe with a new frame number of 32.999999 will not be assigned to frame 33 but to 32. So I have to make a rounding function.(yeah python has built in rounding but that works a bit unpredictable from my experience)

Now, this is only for grease pencil, since that’s what I worked on last. But I’ll make one for regular objects as well.
I guess I have to add a button to the UI as well.