Activity › Forums › Adobe After Effects Expressions › Highlight some words in several text layers
-
Highlight some words in several text layers
Posted by Liviu Ispasoiu on July 30, 2020 at 9:29 amHi, I have some text layers in a comp and I want the words at those numbers to be highlighted, as in the example below. A similar case can be found in this thread https://forums.creativecow.net/readpost/227/35912, but I was not able to make it work for several text layers. Can you please help me to fix it?
Perry Sheppard replied 5 years, 9 months ago 4 Members · 6 Replies -
6 Replies
-
Tomas Bumbulevičius
July 30, 2020 at 12:11 pmHey Liviu, just wondering – how sustainable is solution based on specific word index? And at the same time – how you will make sure indexes are correct?
Last but not least – how many text layers are to be considered in the scheme, or it can vary greatly?
Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH -
Liviu Ispasoiu
July 30, 2020 at 2:13 pmHi Tomas, thank you for your quick reply.
I want to use this with the ability to edit the content and control highlighted words in the essential graphics panel, for instance.
The number of words can vary depending on the content but with a fixed number of lines(rows) – let’s say three. I could use a single text as a paragraph and that would be more convenient. But I can’t really figure out how to animate each line individually. I also thought of looking up the name of the word instead of index. But, for example, if “the” appears in the text several times in the text, then it is highlighted each time it appears. A more advanced method is beyond me. -
Filip Vandueren
July 30, 2020 at 2:19 pmThis would work:
It’s important that the animators are named “word highlighter”.
The lines of text should be in order top to bottom in the timeline, so the layer index of line 1 should be less than that of line 2, etc.An extra text-layer with the word-indexes separated by comma’s is on layer named “indexes”.
Expression Selector, based on Words
my_index_offset=0;
for (i=1; i < index; i++) {
try {
t = thisComp.layer(index-i).text;
test = t.animator("word highlighter");
my_index_offset += t.sourceText.value.trim().split(/\s/g).length;
} catch (e) {
// skip when "word highlighter" animator doesn't exist in previous layer
}
}indexes = eval("[" +thisComp.layer("indexes").text.sourceText.value + "]");
indexes.indexOf(textIndex + my_index_offset) > -1 ? 100 : 0;
-
Filip Vandueren
July 30, 2020 at 2:28 pmHmm.
Better replace that eval() with a split version, that’s more robust:
my_index_offset=0;
for (i=1; i < index; i++) {
try {
t = thisComp.layer(index-i).text;
test = t.animator("word highlighter");
my_index_offset += t.sourceText.value.trim().split(/\s/g).length;
} catch (e) {
// word highlighter doesn't exist in previous layer
}
}indexes = thisComp.layer("indexes").text.sourceText.value.split(",").map( s => parseInt(s));
indexes.indexOf(textIndex + my_index_offset)>-1 ? 100 : 0;
-
Perry Sheppard
July 31, 2020 at 2:28 amThis might not be relevant, but if this would be used in a MOGRT, I associated a similar solution to empty csv data, so the highlighted words can be selected within Premiere.
Not sure how much of a performance hit this takes on the MOGRT (I’m still trying to track down why mine is so slow), but it works well and consistently.
Reply to this Discussion! Login or Sign Up
