Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trying to break text into different lines

  • Trying to break text into different lines

    Posted by David Cabestany on August 28, 2015 at 6:59 pm

    I have a few text layers which need to take their source text from the comp name, it just makes my job easier as I need to replicate the action several times.
    One of the texts is too long and doesn’t fit in one line so I’m trying to break it automatically using the expression below.
    The expression is not returning any errors but it’s not breaking the text either.

    My guess is that it’s missing the bottom part of the expression: “else” and then something
    but I have no idea how to instruct the expression to not break the line.

    Can anyone help?
    Thanks in advance.

    t=thisComp.name;

    if

    (t.length % 6 ==0)
    {
    t +="\r";
    }
    ;
    t;

    David Cabestany replied 11 years ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    August 28, 2015 at 7:18 pm

    Like this maybe:


    maxLen = 6;
    t = thisComp.name;
    if (t.length > maxLen){
    t = t.substr(0,maxLen) + "\r" + t.substr(maxLen);
    }
    t

    Dan

  • David Cabestany

    August 28, 2015 at 7:35 pm

    This one does the trick.

    It’s kind of reversing the function by specifying a max amount of characters per line; the original expression I was trying to use divided the number of characters and if the result was 0 then it would break the line (or at least that’s what I tried). Yours is a much more straightforward solution.

    I’m reading now who substr() works, on your website. I never used it before.

    Thanks a lot Dan.

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