ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Condition based on text value containing certain letters

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Adam Haas
Condition based on text value containing certain letters
on May 9, 2018 at 8:39:21 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?


Return to posts index

Kalleheikki Kannisto
Re: Condition based on text value containing certain letters
on May 12, 2018 at 12:48:29 pm
Last Edited By Kalleheikki Kannisto on May 12, 2018 at 1:20:49 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


Return to posts index

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