Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Break line expression to fit comp width

  • Break line expression to fit comp width

    Posted by Junior Ramos on August 28, 2021 at 7:34 pm

    Hi.

    I’m loading a text file and setting a text layer with each line, but some are too long and exceeding the comp width.

    Anyone knows how can I break a line to fit the comp size using expressions?

    Is there some way of limiting the sourcRectAtTime or convert the text layer from point text to paragraph tex using an expression?

    Thanks in advance.

    Junior Ramos replied 4 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Chris Voelz

    August 28, 2021 at 7:46 pm

    Change your text layer from point to paragraph and then set your text box size to what you want. You can also use \r to add a carriage return in your expression.

  • Junior Ramos

    August 29, 2021 at 2:02 am

    Hi.

    thanks for the reply.

    I’m creating the text layer and inserting the text all by script.

    I could split at some white space or insert the \r. But one line can have 2 words and 7, then how to know when and where to break the line?

    The problem is that I just can see if the line is too long after seeing the screen.

    I’d like something similar to the auto-scale using expression but in this case the text size changes by each line and it’s not what I want.

    I need some simple way of restricting the textbox to the comp width, and once the text reaches this dimension, it breaks the line and so on.

    But I can just figure out a complicated one using a bunch of expressions.

  • Junior Ramos

    August 29, 2021 at 3:29 am

    Well,
    to create a paragraph text you need just set an “addBoxText”.
    The problem is that in the docs (https://ae-scripting.docsforadobe.dev/layers/layercollection/?highlight=addboxtext#layercollection-addboxtext) the “text” parameter is missing, and without it won’t work.

    So, to add point text:
    myTextLayer = comp.layers.addText(text);

    And for paragraph text:

    myTextLayer = parentComp.layers.addBoxText([width, height], text);

    Hope it helps anyone with the same problem.

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