Forums › Adobe After Effects Expressions › change font color of individual words based on special character – captions
-
change font color of individual words based on special character – captions
-
TIneke Van Schalkwyk
February 5, 2023 at 8:43 pmThese 2 scripts (written by Dan) work for a basic text layer but when I try and apply it to my captions text layer which has layer markers (keyframes) to break the text into slides it's not working. Error is shown in image.
txt = thisComp.layer("Input Text").text.sourceText;
txt.replace(/[\[\]']+/g,'');txt = thisComp.layer("Input Text").text.sourceText;idx = textIndex - 1;
txt.split(" ")[idx].indexOf("[") == 0 ? 100 : 0 -
Dan Ebberts
February 5, 2023 at 9:19 pmThe code in your screen grab doesn’t match what you posted. What you posted should work fine with keyframes. The code in your screen grab is somewhat of a hack (using negative time) and that version wasn’t intended to work with keyframed source text.
-
Dan Ebberts
February 6, 2023 at 12:25 amI’m not sure exactly what’s generating the error (I can’t replicate it), but it can’t work set up that way. The expressions assume that the text containing the “[” characters is on a different layer than the expressions, and the expressions take that text and remove the “[” and “]” characters, but still reference them in the original text layer to decide whether or not to color a particular word. So in your setup, with only one text layer, the second expression will never see the “[” characters.
-
TIneke Van Schalkwyk
February 6, 2023 at 12:44 amOk, I’ve saved the ae file if you are able to take a look by any chance?
I use pt_subtitles plugin to import the captions from an srt file which creates the text layer.https://www.dropbox.com/s/gptxbz47jt5wu7t/expressionerror.aep?dl=0
-
Dan Ebberts
February 6, 2023 at 1:26 amI think you’ve got some keyframes with no text, and I’m not sure what happens to textIndex in that case, but you could try replacing the 2nd expression with this:
txt = thisComp.layer("V48020 - TL - V2 - H1(1).srt").text.sourceText;
try{
idx = textIndex - 1;
txt.split(" ")[idx].indexOf("[") == 0 ? 100 : 0;
}catch(e){
0;
}
Log in to reply.