Skip to main content
Alex White
Legend
April 23, 2013
Answered

Detecting keyframe on current time

  • April 23, 2013
  • 1 reply
  • 888 views

Hi everyone,

Is there any fast way to detect if property has a keyframe on current time?

This topic has been closed for replies.
Correct answer Paul Tuersley

You'd use a combination of the nearestKeyIndex(time) and keyTime(index) property methods.

For example:

var activeItem = app.project.activeItem

if (activeItem != null && activeItem instanceof CompItem) {

 

  var prop = activeItem.selectedProperties[0];

  if (prop != null && prop.numKeys > 0) {

    alert("current time = " + activeItem.time + " nearest key time = " + prop.keyTime(prop.nearestKeyIndex(activeItem.time)));

 

    if (prop.keyTime(prop.nearestKeyIndex(activeItem.time)) == activeItem.time) {

      alert("There's a keyframe at this time");

    }

  }

}

1 reply

Paul TuersleyCorrect answer
Inspiring
April 23, 2013

You'd use a combination of the nearestKeyIndex(time) and keyTime(index) property methods.

For example:

var activeItem = app.project.activeItem

if (activeItem != null && activeItem instanceof CompItem) {

 

  var prop = activeItem.selectedProperties[0];

  if (prop != null && prop.numKeys > 0) {

    alert("current time = " + activeItem.time + " nearest key time = " + prop.keyTime(prop.nearestKeyIndex(activeItem.time)));

 

    if (prop.keyTime(prop.nearestKeyIndex(activeItem.time)) == activeItem.time) {

      alert("There's a keyframe at this time");

    }

  }

}

Alex White
Legend
April 23, 2013

Thanks! Work like a charm