Activity › Forums › Adobe After Effects Expressions › Change word color through expressions
-
Change word color through expressions
Posted by Amir Aizat on May 30, 2017 at 8:28 amHi, 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.
Perry Sheppard replied 5 years, 10 months ago 6 Members · 12 Replies -
12 Replies
-
Kevin Camp
May 30, 2017 at 11:57 pmi 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 -
Dan Ebberts
May 31, 2017 at 12:04 amI 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
-
Kevin Camp
May 31, 2017 at 12:08 ami 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 -
Dan Ebberts
May 31, 2017 at 12:50 amSomething 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
-
Kevin Camp
May 31, 2017 at 3:19 pmexcellent. 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 -
Amir Aizat
June 2, 2017 at 7:07 amDan, 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!
-
Joel Bellagamba
June 19, 2020 at 8:13 pmDoes 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!
-
Filip Vandueren
June 21, 2020 at 8:50 amSee this thread where I built rudimentary html parser:
https://forums.creativecow.net/thread/227/45182
-
Joel Bellagamba
June 22, 2020 at 9:44 amWow, you’ve almost got a handy preset there!
Great job and thanks again for sharing.
-
Perry Sheppard
July 13, 2020 at 5:34 amI found this expression (see below) on page 64 of JARLE LEIRPOLL’s Free eBook on Making MOGRTs. He references this thread as the source of the base for the expression.
Here’s the overview from the eBook:
“Use two text layers: one named Text and one named Highlighted Words. Add an expression selector to the Text layer by choosing Animation > Add Text Selector > Expression. Then add a Color animator by choosing Animation > Animate Text > Fill Color > RGB. Change Based On to Words.
Alt-click the stopwatch for Amount and paste the code (below). Now start typing numbers separated by plus signs in the Highlighted Words text layer. The words at those numbers in the main Text layer will change color.”
I’ve been trying to modify the expression to also change the highlighted words to uppercase and bold/fauxbold, but the structure is a little beyond my abilities.
Any help would be appreciated.
string = thisComp.layer("Highlighted Words").text.sourceText.split("+");
result = 0;
for (i = 0; i < string.length; i++){
if (textIndex == parseInt(string[i],10)){
result = 100;
break;
}
}result
Reply to this Discussion! Login or Sign Up