Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change the color of a specific word in a sentence with expression

  • Change the color of a specific word in a sentence with expression

    Posted by Liam Campbell on December 6, 2016 at 3:46 pm

    I’m trying to change the color of specific words that are part of a larger sentence. Is there a way to “access” a string of letters in the source text to change the color of just that word?

    Liam Campbell replied 9 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    December 6, 2016 at 5:49 pm

    This is a simplistic example that might get you started. Add a Fill Animator to your text layer, then add an Expression Selector, then add this expression to the Expression Selector’s Amount property:

    targetWord = “test”;
    txt = text.sourceText;
    idx = txt.indexOf(targetWord);
    if (idx > -1){
    if (textIndex > idx && textIndex <= (idx + targetWord.length)){
    100
    }else{
    0
    }
    }else
    0

    If your text has the word “test” in it, it should be red. This has a lot of limitations though. Only the first occurrence of the word will be colored. It won’t work right if your text is multi-line. It doesn’t account for capitalization (e.g., it won’t match “Test”).

    You could certainly come up with a more robust solution, depending on your requirements.

    Dan

  • Liam Campbell

    December 6, 2016 at 7:01 pm

    Thank you for answering, could you document what some of the lines are doing for me just to help me understand a little bit more what’s going on?

    Thanks

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