Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Condition based on text value containing certain letters

  • Condition based on text value containing certain letters

    Posted by Adam Haas on May 9, 2018 at 8:39 pm

    I’ve been using this script to adjust the anchor point of my text:


    layerTop = this.sourceRectAtTime().top;
    layerLeft = this.sourceRectAtTime().left;
    layerHeight = this.sourceRectAtTime().height;
    layerWidth = this.sourceRectAtTime().width;

    [layerLeft + layerWidth/2, layerTop + layerHeight/2];

    Works great when the text is in all caps. However, if it is lower case and contains any of the following: g,j,p,q,y

    then it’s off. I can do this as it comes, but the idea of this script is that I can paste it on any text I may have and it’ll work.

    So how can I modify this so that it adds or subtracts to the “layerHeight” if “text.sourceText” contains g,j,p,q or y?

    Kalleheikki Kannisto replied 8 years ago 2 Members · 1 Reply
  • 1 Reply
  • Kalleheikki Kannisto

    May 12, 2018 at 12:48 pm

    While it is possible to do that, I’d think simply adding some extra height to the box to cover all instances would work equally well.

    As for your question, you can use a regular expression* (haven’t used them enough to remember the syntax by heart) to check if those letters are found in the string and if so, add to the height. But if you have several lines of text, you’d have to check last line only, which is not that straightforward in AE.

    * Javascript regex

    Kalleheikki Kannisto
    Senior Graphic Designer

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