Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions simple if then statement based on character length

  • simple if then statement based on character length

  • Adam Greenberg

    January 26, 2021 at 2:50 pm

    Hi everyone, I am sure the problem is only with the way I wrote this. I have done and modified countless expressions over the years, but this one isn’t working.

    I want my if then statement to change position by 100 pixels based on character length in a text, so here is my expression in the position property of a different layer.

    a=thisComp.layer(“text”).text.sourceText.length

    if (a>32),[960,540] else [960, 640]


    thanks so much for any help.


    To further explain the reasoning, I plan on making my text a paragraph text with a limited length horizontally, so that once the text starts appearing on the second line, the expression will move the other layer down, basically keeping this layer a certain amount of pixels lower than the text. I think there might even be better way to create this expression based on sourcerectattime for the height, but Im not sure how.


    Thank you

  • Kevin Camp

    January 26, 2021 at 8:17 pm

    I would do it with using sourceRectAtTime().

    Parent the layer to the text layer and try this:

    rect = parent.sourceRectAtTime() ;

    y = rect.top + rect.height ;

    value + [ 0, y ]

  • Trent Armstrong

    January 26, 2021 at 9:14 pm

    Adam,

    I’m curious if it’s not doing what you want or if it’s breaking. I realized after much gnashing of teeth that the new expression engine asks for more coding language like:

    if (a>32) {[960,540]} else {[960, 640]}


    Kevin may have gotten you to the right place, but I wanted to make sure you’re not experiencing a “gotcha”.

    Trent

  • Adam Greenberg

    January 26, 2021 at 10:23 pm

    Trent, it was showing an error the way I wrote it. But I have no way of knowing the exact problem. your expression works perfectly. Thanks so much

  • Adam Greenberg

    January 26, 2021 at 10:24 pm

    Thanks Kevin, yes this looks amazing. I’m going to try this.

    Thanks so much

  • Adam Greenberg

    January 26, 2021 at 10:41 pm

    Kevin, what if I don’t want to parent it. I may have other things that the text layer is doing that I don’t want the null to follow. I figured out how to modify the beginning by writing the following;

    rect = thisComp.layer(“titre”).sourceRectAtTime() ;

    y = rect.top + rect.height ;

    value + [ 0, y-160 ]

    but the problem is the null moves exponentially away from the text, as the text goes into more and more lines. I’m sure it’s an easy fix but I cant figure out the logic on this one, especially rect.top

    Thanks again for any help

  • Trent Armstrong

    January 27, 2021 at 3:11 pm

    Adam,

    That is good info. I think the problem, at least for the syntax, was the braces for the if/then statement.

    if (something) {this} else {that}

    — or —

    if (something) {

    this

    } else {

    that

    }

    I’m not sure about your exponential movement issue, but you might need to multiply the height * .5.

    We’re all pulling for you!

Viewing 1 - 7 of 7 posts

Log in to reply.

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