Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Highlight text in markers.

  • Highlight text in markers.

    Posted by Matt Volp on May 9, 2017 at 11:02 am

    Hello again,

    Firstly, I’ve been a long time reader of this forum and I’ve only recently posted on here for expression help. The response so far has been awesome, thanks to all who contribute and help others out! I hope to be able to do the same for others soon.

    Currently, I have this expression on an expression selector inside a fill color animator.

    h = thisComp.layer(“CTRL | Highlights”);
    n = 0;
    if (h.marker.numKeys > 0){
    n = h.marker.nearestKey(time).index;
    if (h.marker.key(n).time > time) n–;
    if (n > 0) refText = h.marker.key(n).comment;
    }
    words = refText.replace(/\r?\n|\r/g, ‘ ‘).replace(/\s{2,}/g, ‘ ‘).split(” “);
    val = 0;
    thisText = text.sourceText.replace(/\r?\n|\r/g, ‘ ‘).replace(/\s{2,}/g, ‘ ‘);
    thisWord = thisText.split(” “)[textIndex-1];
    for(i = 0; i < words.length; i++){ if (words[i] == thisWord){ val = 100; break; } } val It highlights words that are in the comment of the nearest previous marker. But, when there are no markers on the layer at all, the expression breaks. Is there something I can add which says if there are no markers, just highlight nothing. Matt

    Michael Myers replied 6 years, 2 months ago 3 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    May 9, 2017 at 9:09 pm

    Try it this way:


    h = thisComp.layer("CTRL | Highlights");
    n = 0;
    if (h.marker.numKeys > 0){
    n = h.marker.nearestKey(time).index;
    if (h.marker.key(n).time > time) n--;
    if (n > 0) refText = h.marker.key(n).comment;
    }

    if (n > 0){
    words = refText.replace(/\r?\n|\r/g, ' ').replace(/\s{2,}/g, ' ').split(" ");
    val = 0;
    thisText = text.sourceText.replace(/\r?\n|\r/g, ' ').replace(/\s{2,}/g, ' ');
    thisWord = thisText.split(" ")[textIndex-1];
    for(i = 0; i < words.length; i++){
    if (words[i] == thisWord){
    val = 100;
    break;
    }
    }
    val;
    }else
    0

    Dan

  • Michael Myers

    February 21, 2020 at 5:43 pm

    Hey, sorry to resurrect this post from a few years back, but I’m currently trying to automate single word text highlighting in some AE templates I’m building. Do you have a project or sample .ae file I could see?

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