Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions marker.numKeys works sometimes, sometimes not

  • marker.numKeys works sometimes, sometimes not

    Posted by Anders Hattne on October 31, 2024 at 10:19 am

    Hello, I’ve got this expression to display the layer’s marker comments. The expression works most of the time, and other times it works but displays an error message. I get a message saying the property has no keyframe(s).
    What can I do to make it consistently work?

    s = thisComp.layer(“Notes”);
    v = “”; // variable for comment output
    k =1; // here I store my marker keyframe number. I put 1 to see if it works better than 0
    if (s.marker.numKeys > 0) {
    k = s.marker.nearestKey(time).index;
    if (time < s.marker.key(k).time) k–; // this to make the keynumber look backwards

    v = s.marker.key(k).comment;
    // here I get an error saying the property has no keyframe 0 !!!
    }
    else {v = ” “}
    v

    Ming Hsu replied 1 week, 3 days ago 4 Members · 5 Replies
  • 5 Replies
  • Yoan Boisjoli

    October 31, 2024 at 11:19 am

    I think the error occurs because the expression sometimes sets the key index to 0, and After Effects keyframes start at 1, making index 0 invalid.

    Try something like this:

    s = thisComp.layer("Notes");
    v = ""; // Variable for comment output
    if (s.marker.numKeys > 0) {
    k = s.marker.nearestKey(time).index;
    // Check if the current time is before the nearest key's time
    if (time < s.marker.key(k).time) {
    k--; // Decrement k to get the previous key
    // Ensure k does not go below 1
    if (k < 1) {
    v = ""; // Optionally, set to a default value if no previous key exists
    } else {
    v = s.marker.key(k).comment;
    }
    } else {
    v = s.marker.key(k).comment;
    }
    } else {
    v = " "; // Default value if there are no markers
    }
    v
  • Anders Hattne

    October 31, 2024 at 11:53 am

    Ah, I think I understand. Not sure what the term is but most properties seem to start counting at 0. Keyframes start at 1?

    I’ll have a closer look thanks. Using k– with nearestKey was a breakthrough for me 🙂 Finally got over that hurdle!

  • Yoan Boisjoli

    October 31, 2024 at 12:16 pm

    Yeah! After Effects’ keyframe indices start at 1. This means the first keyframe is key(1), the second is key(2), and so on !

  • Dan Ebberts

    October 31, 2024 at 3:52 pm

    You can minimize the code a little like this:

    m = thisComp.layer("Notes").marker;
    v = "";
    if (m.numKeys > 0){
    k = m.nearestKey(time).index;
    if (time < m.key(k).time) k--;
    if (k > 0) v = m.key(k).comment;
    }
    v
  • Ming Hsu

    November 1, 2024 at 2:01 am

    m = thisComp.layer(“Shape Layer 1”);

    txt = “”;

    if (m.marker.numKeys > 0){

    n = m.marker.nearestKey(time).index;

    if (time < m.marker.key(n).time) n–;

    if (n > 0) txt = m.marker.key(n).comment;

    }

    txt

    Maybe you can try this 🙂

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy