Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Paragraph leading expression

  • Filip Vandueren

    March 18, 2021 at 9:25 am

    Hi Jamel, try this:

    txt=text.sourceText;
    fs= txt.style.fontSize * 1000/effect("boxWidth")("Slider");
    ld = txt.style.leading * 1000/effect("boxWidth")("Slider");
    style.setFontSize(fs).setAutoLeading(false).setLeading(ld);

    Important: if you want to change leading or fontsize in the character palette, also first disable the sourceText expression!

    you can do it all in code too like this for 60/90 size/leading:

    txt=text.sourceText;
    fs= 60 * 1000/effect("boxWidth")("Slider");
    ld = 90 * 1000/effect("boxWidth")("Slider");
    style.setFontSize(fs).setAutoLeading(false).setLeading(ld);

  • Filip Vandueren

    March 18, 2021 at 9:28 am

    Here’s a small adjustment that will support auto leading:

    txt=text.sourceText;
    fs= txt.style.fontSize * 1000/effect("boxWidth")("Slider");
    ld = (txt.style.autoLeading ? fs*1.2 : txt.style.leading * 1000/effect("boxWidth")("Slider"));
    style.setFontSize(fs).setAutoLeading(false).setLeading(ld);
  • Jamel Ghabbara

    March 31, 2021 at 5:49 am

    Hi Filip

    Sorry for answering a little bit late, my machine is dead last week and i had to find a way to recover my files… long story…

    i wanna thank you again and again… a lot of time

    the code works fine, but when i try to link the source text to another text it doesn’t work, can you tell me why ? ( i just changed the first line of code )
    THANK YOU FILIP

    txt=thisComp.layer(“TEXT”).text.sourceText;

    fs= txt.style.fontSize * 1000/effect(“boxWidth”)(“Slider”);

    ld = (txt.style.autoLeading ? fs*1.2 : txt.style.leading * 1000/effect(“boxWidth”)(“Slider”));

    style.setFontSize(fs).setAutoLeading(false).setLeading(ld);

  • Filip Vandueren

    March 31, 2021 at 6:02 am

    Hi jamel, “style” is the current layer’s style, in your case it needs to be the other layer’s style.

    so the final line should be:

    txt.style.setFontSize(fs).setAutoLeading(false).setLeading(ld).setText(txt);

  • Jamel Ghabbara

    March 31, 2021 at 10:18 am

    man.. i dont know who you are, but ill find you, and ill offer u a cup of coffee <3 <3

    Thanks A Lot Filip

  • Jamel Ghabbara

    April 4, 2021 at 3:39 am

    Hi Filip

    Just a small question:
    i want to get the right Height of the text, the problem that i don’t get the right one when i use sourceRectAtTime. for example: if the paragraph is 2 lines, even if i move a little bit the Solid to modify the bouding and the paragraph stays 2 lines, the Height changes, its supposed to stay the same value, unless the paragraph is 3 lines.

  • Jamel Ghabbara

    April 4, 2021 at 3:46 am
  • Filip Vandueren

    April 5, 2021 at 8:48 am

    Hi Jamel,

    The value is correct: it is the height of the sourceText. But you need to multiply a layer’s sourceRect height by scale[1]/100 to get the actual pixel-size of the layer.

    And if the layer is parented, you also need to take into account the scale of parents etc.

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