Skip to main content
New Participant
March 27, 2024
Question

Know a keyframe's exact time on timeline

  • March 27, 2024
  • 1 reply
  • 265 views

I want to know if there's an expression to know the time at which a keyframe is positioned on a timeline (i.e. if a keyframe is at second 2:00, I want an expression telling me that the keyframe's time is 2:00 or its corresponding frame).

 

Can anybody help me, please?

This topic has been closed for replies.

1 reply

Brainiac
March 27, 2024

Somthing like this:

 

Get Key Index From Time/Frame:

 

target = thisComp.layer("Shape Layer 1").position;
frame = 60;
// or 
// frame = timeToFrames(2);
result = 'not found';
for (i = 1; i <= target.numKeys; i++) {
  if (timeToFrames(target.key(i).time) == frame) {
    result = 'key: ' + i;
    break
  }
}
result

 

 

Get Key Time From From Key Index:

target = thisComp.layer("Shape Layer 1").position;
if (target.numKeys) {
  numKey = 2;
  target.key(numKey).time + 's';
  // or
  // timeToFrames(target.key(numKey).time) +' frames';
} else {
  'no keyframe'
}

 

New Participant
April 1, 2024

Thank you very much! I'lk try it out to see if it works!