Feature Request - Jump to frame at midpoint frame of two keyframes

Greetings, I find myself many times manually placing my timeline cursor at the midpoint frame that exists between two keyframe when I’m trying to figure out where I need keyframes on a long clip. While incremental frame skip setting is useful for me in a quick playback, I don’t really like setting my frames incrementally to jump every 5 or 8 frames for setting keyframes, because I find that most of the time, the keyframe spacing varies, but setting a keyframe at the midpoint frame between to keyframes is something I do do a lot.

Example. I’ll keyframe at frame 1, then keyframe at frame 80, then I’ll jump to frame 40 and add a keyframe (realistically more like frame 38-42 since I’m usually just eyeballing the midpoint frame), then I’ll jump midway between frame 1 and frame 40, add a keyframe around frame 20, then jump midway between frame 40 and 80 and a keyframe around frame 60. It would be great if I could hit a key to jump to the midpoint frame or nearest midpoint frame to speed up the manual midpoint selecting.

Thanks for your consideration :slight_smile:

We can let @marco know about the feature request and see if it’s something we can implement in the schedule and if we think it will be useful for other users. Thank you for your suggestion. :slight_smile:

Paste this into your resources/scripts/keybinds.py file or just ceate a .py file in resources/scripts/gui and paste this in there:

from fx import *

def goto_prev_key_midpoint():
	sel = selection()
	if len(sel) == 1:
		object = sel[0]
		if isinstance(object, Shape):
			prop = object.property("path")
			t = prop.getPrevKeyTime(player.frame)
			if t != None:
				player.setFrame(int((t + player.frame) / 2))

def goto_next_key_midpoint():
	sel = selection()
	if len(sel) == 1:
		object = sel[0]
		if isinstance(object, Shape):
			prop = object.property("path")
			t = prop.getNextKeyTime(player.frame)
			if t != None:
				player.setFrame(int((t + player.frame) / 2))

bind('Alt+z', goto_prev_key_midpoint)
bind('Alt+x', goto_next_key_midpoint)

This binds Alt+z to “go to the midpoint of the current frame and the previous shape keyframe”, and Alt+x to “go to the midpoint of the current frame and the next shape keyframe”.
It currently requires a single selected shape but could be easily extended to look at the next keyframes of all selected shapes, trackers, etc.

2 Likes

Thanks for letting me know, much appreciated!!

Awesome, looking forward to trying this out today. I’d say my most common use is if I’m working on a single shape or I might have 2 or 3 shapes selected at once, when I’m trying to adjust them together and want to maintain tangency between the shapes.

Assuming I have the same Keyframe A and Keyframe B on a few shapes, with the code as is, would I be able to have 3 shapes selected (e.g. neck shape, chin shape, bottom lip shape) and “go to” the midpoint frame (not keyed yet) Frame B, or would I have to only select one of the 3 shapes before hitting alt+X or alt+z? Thanks again :pray:t3:

Yes, just change these lines:

if len(sel) == 1:

to:

if len(sel) != 0:

1 Like

Hi Paul,

I pasted the code at the very end of my keybinds.py, but it doesn’t seem to do any action when i hit (since I’m on a Mac) opt+z, or opt+x. Any suggestions? Thanks :slight_smile:

@persyst I followed Paul’s instructions and it works for me on both Mac and Windows. I made two files–one for using the script with one shape (the original code) and another for multiple shapes.
scripts.zip (724 Bytes)

Remove any previous modifications you may have made and place one of the attached files in resources/scripts/gui

Ah perfect thanks for checking Marco! I just realized I had pasted them into my v2020.5 and not my v2021.5 folder. Just tried the multishape and works great!! Thanks @paul.miller for the code as well!!