Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Is it possible to change the space after paragraph option via script?

  • Is it possible to change the space after paragraph option via script?

    Posted by Andrei Popa on February 8, 2022 at 10:41 am

    I did some research and saw that this would not possible.

    I am curious if there is some workaround. I need to generate a lot of text layers and some have different space after paragraph option. They are textboxes that automatically cut lines, so increasing the leading is not an option.

    Filip Vandueren replied 4 years, 3 months ago 3 Members · 4 Replies
  • 4 Replies
  • Tomas Bumbulevičius

    February 10, 2022 at 8:59 am

    Hey Andrei, any chance you could share a visual reference of what you are trying to achieve? That could help to eliminate the guesswork!

  • Filip Vandueren

    February 10, 2022 at 1:59 pm

    Hi Andrei, AFAIK, you can’t set any paragraph options via scripting.

    Here’s a dirty workaround using text-animators:

    text animators with expression selectors based on characters skip over the “\r” character so it’s hard to detect them while keeping textIndex and the characters of sourceText in sync.

    So to start, we’ll need an expression on the sourceText (or it can be done in your scripting) to replace every linebreak with an invisible zero-width space (unicode \0x200B) followed by a linebreak. This won’t alter anything of your layout, but the space does count as a character for the textIndex inside the expression selector.

    So the expression for sourceText:

    value.replace(/\r/g,"\u200b\r");

    Next we need a Text-Animator:

    • add a position property with value [0px, 10,000.0px]
    • Add an Expression selector based on characters (and remove the default range selector)
    • change the amount expression to:
    txt = text.sourceText.value.replace(/\r+/g,"");
    space_after = 90;
    paragraphNumber = txt.substr(0,textIndex).split("\u200b").length-1;
    paragraphNumber*space_after/100;

    This first line strips out the linebreaks from the sourcetext so the javascript string’s indexes and the way after effects counts characters via textIndex line up.

    space_after is the number of pixels you want each next paragraph to be pushed down.

    The variable paragraphNumber counts how many times an invisible space is present, those represent a “countable” paragraph break.

    The result of expression selectors needs to be a percentage between -100 and +100 of how much the position property gets applied, so using the set vertical change of 10,000 pixels means we can do an easy division to make for example 90 pixels translate to 0.9%

    If you need more then 10,000 pixels (in this example more than 111 paragraphs) simply add an extra order of magnitude to both the position [100,000px] and the division in the expression (/1000)

    Hope that works out.

    Filip

  • Andrei Popa

    February 12, 2022 at 7:47 am

    Hi Filip, that’s a great solution. I should treat text animators with more respect 😀

  • Filip Vandueren

    February 12, 2022 at 7:55 am

    Let me know if you run into any edge cases (I haven’t tested with stuff like non Latin text with lots of diatcritic modiefiers and such, which also cause the animator textIndex to differ from the string character index

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