Forums › Adobe After Effects Expressions › Paragraph leading expression
Paragraph leading expression
jamel ghabbara
March 17, 2021 at 12:48 pmHi Guys
few ays ago i posted a problem about controlling paragraph bounding using expressions
Filip Vandueren Helped me that day, thanks to him again, i didn t want to bather him with more questions, the code worked well only for one thing:
the leading is not fixed. when i try to addl style.setLeading(…) it ruins everything.you can find here the project with code from Filip.
thank a lot guys
Filip Vandueren
March 18, 2021 at 9:25 amHi 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 amHere’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 amHi 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 FILIPtxt=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 amHi 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 amman.. 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 amHi 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 amFilip Vandueren
April 5, 2021 at 8:48 amHi 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.
Log in to reply.