decorative banner

Accessing keyframes and markers in expressions


    You can now write expressions that access keyframes and markers. These expressions are useful for accessing values at particular times as delineated by keyframe and marker locations and values. Access keyframes or markers using the following attributes and methods:

    this_comp.marker(marker_num)

    Returns the time of a composition marker. You can use this to fade out a layer's opacity at the time where the marker resides--for example:

    mark_time = this_comp.marker(1);

    linear(time, mark_time - .5, mark_time, 100, 0)

    num_keys

    Returns the number of keyframes in a property.

    nearest_key(time)

    Returns the keyframe object nearest to a designated time.

    key(idx)

    Returns the keyframe by number. For example, key(1) returns the first key.

    When you access a key object, you can get time, index, and value properties from it. For example, the following expression gives you the value of the third position key:

    position.key(3).value

    The following expression, when written on a layer's animated Opacity property, ignores the keyframe values and only uses the keyframes' placement in time to determine where a flash should occur:

    d = Math.abs(time - nearest_key(time).time);

    ease_out(d, 0, .1, 100, 0)

    marker

    Returns the marker property for a layer. A marker property is unlike other properties such as Position in that the only methods and attributes available from it are key(), nearest_key, and num_keys. You can retrieve the keys in two ways: either by index, for example, as in the following expression:

    marker.key(1)

    You can also retrieve it by the name of the marker, as typed in the comment field in the marker dialog box:

    marker.key("foo")

    The value for marker keys is a string name, instead of a numeric value. For example, note the following expression, written on a layer's Opacity property:

    m1 = marker.key("Start").time;

    m2 = marker.key("End").time;

    linear(time, m1, m2, 0, 100);