Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Highlight some words in several text layers

  • Tomas Bumbulevičius

    July 30, 2020 at 12:11 pm

    Hey Liviu, just wondering – how sustainable is solution based on specific word index? And at the same time – how you will make sure indexes are correct?

    Last but not least – how many text layers are to be considered in the scheme, or it can vary greatly?

    Find out more:
    Motion Graphics Design & After Effects Tutorials
    On YT
    On VH

  • Liviu Ispasoiu

    July 30, 2020 at 2:13 pm

    Hi Tomas, thank you for your quick reply.
    I want to use this with the ability to edit the content and control highlighted words in the essential graphics panel, for instance.
    The number of words can vary depending on the content but with a fixed number of lines(rows) – let’s say three. I could use a single text as a paragraph and that would be more convenient. But I can’t really figure out how to animate each line individually. I also thought of looking up the name of the word instead of index. But, for example, if “the” appears in the text several times in the text, then it is highlighted each time it appears. A more advanced method is beyond me.

  • Filip Vandueren

    July 30, 2020 at 2:19 pm

    This would work:

    It’s important that the animators are named “word highlighter”.
    The lines of text should be in order top to bottom in the timeline, so the layer index of line 1 should be less than that of line 2, etc.

    An extra text-layer with the word-indexes separated by comma’s is on layer named “indexes”.

    Expression Selector, based on Words

    my_index_offset=0;
    for (i=1; i < index; i++) {
    try {
    t = thisComp.layer(index-i).text;
    test = t.animator("word highlighter");
    my_index_offset += t.sourceText.value.trim().split(/\s/g).length;
    } catch (e) {
    // skip when "word highlighter" animator doesn't exist in previous layer
    }
    }

    indexes = eval("[" +thisComp.layer("indexes").text.sourceText.value + "]");
    indexes.indexOf(textIndex + my_index_offset) > -1 ? 100 : 0;

  • Filip Vandueren

    July 30, 2020 at 2:28 pm

    Hmm.
    Better replace that eval() with a split version, that’s more robust:


    my_index_offset=0;
    for (i=1; i < index; i++) {
    try {
    t = thisComp.layer(index-i).text;
    test = t.animator("word highlighter");
    my_index_offset += t.sourceText.value.trim().split(/\s/g).length;
    } catch (e) {
    // word highlighter doesn't exist in previous layer
    }
    }

    indexes = thisComp.layer("indexes").text.sourceText.value.split(",").map( s => parseInt(s));
    indexes.indexOf(textIndex + my_index_offset)>-1 ? 100 : 0;

  • Liviu Ispasoiu

    July 30, 2020 at 2:40 pm

    Hi Filip, this works very well. Thank you so much!

  • Perry Sheppard

    July 31, 2020 at 2:28 am

    This might not be relevant, but if this would be used in a MOGRT, I associated a similar solution to empty csv data, so the highlighted words can be selected within Premiere.

    Not sure how much of a performance hit this takes on the MOGRT (I’m still trying to track down why mine is so slow), but it works well and consistently.

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