Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Expression Selector: character before/after?

  • Expression Selector: character before/after?

  • Jeff Hinkle

    April 26, 2021 at 6:42 pm

    No matter how many Google searches and YouTube videos, I just can’t make this work. I got it close but it seems to have a life of its own that messes with my troubleshooting.

    Short version, I want it to look through a text layer, find the letter “A,” then check the letter before that and, if it matches a letter from a predefined array, adjust the tracking before. A second Animator would do the same for the letter after the “A.” Basically the font has some wonky kerning on the “A”s in certain character combinations and I’m trying to auto-fix it for a mogrt.

    So I set up a Tracking Animator, added an Expression selector and (after lots of Google hunting) cobbled together this:

    a=text.sourceText;
    if (a[textIndex-1] == "a") {
    b=a.charAt(textIndex-2); //check letter before the A
    if (b=="a" || b=="e" || b=="k" || b=="l" || b=="q" || b=="x" || b=="z")100 else 0
    }
    else 0 //this doesn't seem necessary but it failed without it

    Most of which probably isn’t right, but it seems to be almost working (I swear, once it actually did work). It’s just apparently not checking the previous character and just applying it to every “A” regardless. I originally tried setting up the comparison with a nested For loop and an Array, but that threw everything into chaos.

    I’m guessing it has to do with not really understanding how textIndex functions. Am I close? Way off? This even possible?

  • Dan Ebberts

    April 26, 2021 at 9:00 pm

    You were pretty close. I think this will work (as long as your text is only one line):

    a=text.sourceText.value;

    if (textIndex > 1 && a[textIndex-1] == "a") {

    b=a[textIndex-2]; //check letter before the A

    (b=="a" || b=="e" || b=="k" || b=="l" || b=="q" || b=="x" || b=="z") ? 100 : 0;

    }

    else 0

  • Jeff Hinkle

    April 26, 2021 at 9:55 pm

    As always, your knowledge and help are amazing. Many thanks!

    One more question, if I may: when duplicating the Animator to adjust the Tracking after the “A,” it seems to only work on the last “A” in the line and the caution arrow icon/alert message keeps blipping on and off like it’s thinking about failing. I’m sure it’s something to do with my changes to the code, although I only changed the – to a + in this line:

    b=a[textIndex+2]; //check letter after the A

    But the Before works like a charm! Really appreciate the help!

  • Dan Ebberts

    April 27, 2021 at 12:36 am

    I think this is what the After would look like:

    a=text.sourceText.value;

    if (textIndex > 1 && a[textIndex-2] == "a") {

    b=a[textIndex-1]; //check letter after the A

    (b=="a" || b=="e" || b=="k" || b=="l" || b=="q" || b=="x" || b=="z") ? 100 : 0;

    }

    else 0

  • Jeff Hinkle

    April 27, 2021 at 1:58 pm

    Once I changed the tracking type to Before, that worked like a charm. Still don’t fully get how textIndex works but this helps it make a bit more sense. Thank you so much!

  • Jim Lucas

    July 12, 2021 at 6:39 pm

    Hello Dan !
    I have an issue with a expression which looks like this one.
    I would like to hide the first and the last letter of a line.
    For now, I just managed to hide the first letter of the line.

    Source texte :

    “|” + text.sourceText + “|”

    Selector expression :

    if (textIndex > 1 ) 0 else 100

    Sorry i m not a expert ahah.
    In case you have some time to spare, I would be very grateful.

  • Dan Ebberts

    July 12, 2021 at 8:18 pm

    Try this:

    textIndex > 1 && textIndex < textTotal ? 0 : 100
  • Jim Lucas

    July 13, 2021 at 9:09 am

    Insane !
    Thank you for your answer, this is the first question I asked on Creative Cow and you were so quick to respond.
    Thank you so much!
    <3

Viewing 1 - 8 of 8 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy