ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Highlight text in markers.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Matt Volp
Highlight text in markers.
on May 9, 2017 at 11:02:35 am
Last Edited By Matt Volp on May 9, 2017 at 11:56:12 am

Hello again,

Firstly, I've been a long time reader of this forum and I've only recently posted on here for expression help. The response so far has been awesome, thanks to all who contribute and help others out! I hope to be able to do the same for others soon.

Currently, I have this expression on an expression selector inside a fill color animator.

h = thisComp.layer("CTRL | Highlights");
n = 0;
if (h.marker.numKeys > 0){
n = h.marker.nearestKey(time).index;
if (h.marker.key(n).time > time) n--;
if (n > 0) refText = h.marker.key(n).comment;
}
words = refText.replace(/r?n|r/g, ' ').replace(/s{2,}/g, ' ').split(" ");
val = 0;
thisText = text.sourceText.replace(/r?n|r/g, ' ').replace(/s{2,}/g, ' ');
thisWord = thisText.split(" ")[textIndex-1];
for(i = 0; i < words.length; i++){
if (words[i] == thisWord){
val = 100;
break;
}
} val

It highlights words that are in the comment of the nearest previous marker.

But, when there are no markers on the layer at all, the expression breaks. Is there something I can add which says if there are no markers, just highlight nothing.

Matt


Return to posts index

Dan Ebberts
Re: Highlight text in markers.
on May 9, 2017 at 9:09:07 pm

Try it this way:


h = thisComp.layer("CTRL | Highlights");
n = 0;
if (h.marker.numKeys > 0){
n = h.marker.nearestKey(time).index;
if (h.marker.key(n).time > time) n--;
if (n > 0) refText = h.marker.key(n).comment;
}

if (n > 0){
words = refText.replace(/\r?\n|\r/g, ' ').replace(/\s{2,}/g, ' ').split(" ");
val = 0;
thisText = text.sourceText.replace(/\r?\n|\r/g, ' ').replace(/\s{2,}/g, ' ');
thisWord = thisText.split(" ")[textIndex-1];
for(i = 0; i < words.length; i++){
if (words[i] == thisWord){
val = 100;
break;
}
}
val;
}else
0



Dan



Return to posts index

Michael Myers
Re: Highlight text in markers.
on Feb 21, 2020 at 5:43:29 pm

Hey, sorry to resurrect this post from a few years back, but I'm currently trying to automate single word text highlighting in some AE templates I'm building. Do you have a project or sample .ae file I could see?


Return to posts index

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