ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change word color through expressions

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Amir Aizat
Change word color through expressions
on May 30, 2017 at 8:28:53 am

Hi, I'm trying to create a Live Text Template for Premiere Pro using After Effects.

So far I've had pretty much everything done except for changing the color of a specific word using expressions.

For example, the video editors type in a 5 word sentence in Premiere Pro, and then they want the 1st and 4th word to be colored differently for emphasis, so they would just need to type in "1+4" in Live Text Template box in Premiere.

Is this even possible in the first place?

Thank you.


Return to posts index

Kevin Camp
Re: Change word color through expressions
on May 30, 2017 at 11:57:25 pm
Last Edited By Kevin Camp on May 31, 2017 at 12:00:03 am

i think so... but you'll need to have an animator for each possible word. so if you think they could have ten words, then you'll need ten animators....

try this:

create a text layer named 'hilite' (you can name it something else, but you'll need to adjust the expressions). this will be the field they type the numbers into.

then on your text layer with the text, add a fill color animator, set the 'based on' property to 'words', then add an expression selector, and add this expression to the amount:
hilite = thisComp.layer("hilite").text.sourceText.split("+");
txt = text.sourceText;
if ( textIndex == hilite[ 0 ] ) 100 else 0;

assuming you have text in that text layer, if you type a 1 in the 'hilite' text field, the first word should highlight.
to have more words highlight, duplicate that animator. change the amount expression in that animator to this:
wrds = 2;
hilite = thisComp.layer("hilite").text.sourceText.split( "+" );
txt = text.sourceText;
if ( hilite.length > wrds - 1 ) {
if ( textIndex == hilite[ wrds - 1 ] ) 100 else 0;
} else {
0;
}

now if your text field has 3 or more words, and you type "1+3" in the 'hilite' field, words one and 3 should highlight.
to allow more words to highlight, you just need to duplicate that 2nd animator, but change the value of 'wrds' to one number higher each time you duplicate the animator... so 2, then 3, etc. until you have enough animators to cover the maximum number of words that you think they would type.

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Dan Ebberts
Re: Change word color through expressions
on May 31, 2017 at 12:04:18 am

I think you could do it with a single animator if you add an expression selector that compares the textIndex to each of the indexes in the string.

Dan



Return to posts index


Kevin Camp
Re: Change word color through expressions
on May 31, 2017 at 12:08:23 am

i did try something like that with a for loop, but it seemed to cancel out the highlight for the earlier words... i.e., if 1+4 was entered, when it highlighted the 4th word, it set the first word back to the original color...

but you may be thinking of a more robust way of handling that.

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Dan Ebberts
Re: Change word color through expressions
on May 31, 2017 at 12:50:25 am

Something like this for the expression selector amount:


hilite = thisComp.layer("hilite").text.sourceText.split("+");
result = 0;
for (i = 0; i < hilite.length; i++){
if (textIndex == parseInt(hilite[i],10)){
result = 100;
break;
}
}
result



Dan



Return to posts index

Kevin Camp
Re: Change word color through expressions
on May 31, 2017 at 3:19:18 pm

excellent. setting the default value to 0 and then breaking the condition was pretty clever.

i had used else 0 in my earlier attempt, which was why it set any words prior to the last word back to the origin color...

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index


Amir Aizat
Re: Change word color through expressions
on Jun 2, 2017 at 7:07:29 am

Dan, Kevin,

Thank you so much, it worked perfectly and I learned something new about expressions too.

I couldn't have asked for a better solution!


Return to posts index

Simon Brough
Re: Change word color through expressions
on Jun 19, 2020 at 8:13:20 pm

Does anyone know if changing a word color is possible within the text source itself (and without the need for an additional control layer).

So, by entering something like "change the *text color* using double asterisks" the user can highlight the word to recolor by simply enclosing it within two asterisks?

This is all very relevant and useful in 2020 BTW!


Return to posts index

Filip Vandueren
Re: Change word color through expressions
on Jun 21, 2020 at 8:50:32 am

See this thread where I built rudimentary html parser:

https://forums.creativecow.net/thread/227/45182



Return to posts index


Simon Brough
Re: Change word color through expressions
on Jun 22, 2020 at 9:44:25 am

Wow, you've almost got a handy preset there!

Great job and thanks again for sharing.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]