Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Text highlight (expression selector)

  • Yoan Boisjoli

    February 23, 2021 at 3:50 pm

    Yeah I started playing with it! It’s pretty cool! I’ve had the brackets “[]” replace with a zero width space (“\u200b”) so I can easily target it with other expression selector (color for example).

    I’ll try to see if I can have the spaces between words be highlighted too when more than a word is selected in between brackets. I’ll let you know !

  • Filip Vandueren

    February 23, 2021 at 8:01 pm

    It’s not that easy I believe, because the brackets could span multiple lines and you have to test for that.

    Like I hinted, usually just a bit of extra horizontal padding can bleed them together.

    BTW: I haven’t actually tested it in Premiere ? I hope it doesn’t break there ?

  • Yoan Boisjoli

    March 24, 2021 at 7:21 pm

    Hey Filip, been awhile! I finally got to test everything out in premiere. I gave the choice of color control for text, box and highlighted text and it works well ! It’s a bit slow (lots of calculations!) but it runs well as a mogrt !

    I wanted to thank you cause I was really stuck with that one !

  • Yoan Boisjoli

    March 24, 2021 at 7:23 pm

    Ah and by the way, when you mention JSON.parse or stringify, is it a way to call back an expression written in another layer?

  • Filip Vandueren

    March 25, 2021 at 7:57 am

    Hi Yoan,

    I use it to precompute some values in a text-layer, and then use the output of that textlayer as data in another expression.

    If the result of a textlayer is just string we need to use, or a number, then you can simply get the value or value.parseFloat() of the textlayer, but in some cases you want to precompute a list of values or a list of key/value pairs.

    a JSON type object is ideal for this.

    So the expression on my precompute text layer ends with JSON.stringify(myStuff);

    -> this turns the object or list of data I have into “readable/parseable” sourcecode including brackets, quotes,…

    And where I want to use that information, I do JSON.parse(textlayer.text.sourceText.value) to “read” the generated sourcecode of the data object, and so the data becomes part of the expression.

    Before the new Javascript engine, the alternative was to use eval(), which can do even more (it can actually execute functions and statements, not just import a data object)

  • Filip Vandueren

    March 25, 2021 at 7:59 am

    So again to clarify: it doesn’t let another expression see inside the expression code of another property, but it’s a way to format the resulting string-value of a sourceText expression into something another expression can easily interpret.

  • Yannick Michel

    March 3, 2023 at 12:36 pm

    Hi Filip and Yoan,
    I was looking through your thread because I need something quite similar to what you have done but a little different. Let me explain: I need to create a .mogrt for my colleagues where they can highlight multiple words in a text. And the idea is to have a text input where they write their text and another text input where they write the words they want to highlight. Here you can see that I succeed to highlight one word, but I can’t figure out how to highlight multiple words.
    here is the expression I use to highlight one word:

    txt=thisComp.layer(“Highlight”).text.sourceText;

    words = txt.split(/\s/);

    RE = new RegExp(words,”g”);

    hl=text.sourceText.replace(RE, function($0) {

    return ‘~’.repeat($0.length);

    });

    if(hl.charAt(textIndex-1) == ‘~’) { 100 } else { 0 };

    I found some code on workbench youtube channel. I know I need a loop

    for (i=0, i<words.length, i++){}
    But since I am still no master in expression, I don’t know how to write it down. So if one of you hase the answer, it would be great.

    Thank you

  • Filip Vandueren

    March 11, 2023 at 2:33 pm

    Hey Yannick,

    I would use this code in an expression selector based on Words:

    thisWord = text.sourceText.value.split(/[\s\3]+/)[textIndex-1];
    wordList = thisComp.layer("wordlist").text.sourceText.value.split(/[\s\3]+/).map(e => e.toLocaleLowerCase());
    wordList.includes(thisWord.replace(/[\.,?!…:;=]$/gi,'').toLowerCase()) ? 100 : 0;

    It does a few extra things so it also matches words regardless of case (everything is converted to lowercase), and it also matches a word when that is immediately followed by a punctuation mark (you may want to extend that list).

  • Emma Beinish

    November 29, 2023 at 12:56 pm

    Hi Filip, hope you’re well !

    This MOGRT is literally what I’m looking for, well done for building it

    I was just wondering how you would go about building this exact same MOGRT. only using LegacyExtend Script? (I’m a beginner with MOGRTS)

    Many thanks,

  • Filip Vandueren

    November 29, 2023 at 9:59 pm

    Hi Emma,

    you’re starting from the .Aep I shared earlier ?

    It uses Json parse and stringify, which can kind of be replaced with eval(),

    and it also used styling of the sourceText (not possible in extendscript), to force the highlight marker to use a ceratin font, leading and fontsize, but if those are just set manually, it works equally well.

    so this version does I think what you need:

Page 2 of 3

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