Copy link to clipboard
Copied
Hey all!
I'm building a fancy template thingy again. This time I have rounded text boxes (created using Simple Choker -> Minimax -> Tint -> Roughen Edges) and that works fine. However, the text will be up to three lines long, and this box method only looks good on a single line, since it only adapts to the outline of the whole text block, not per line.
So my idea is:
I'll have a separate text box for the input (which is invisible in the final output). I'm taking the text content from there, split it up on each manual entered line break and send each bit of text to one of three text layers.
Text input:
This is some
Text with three
Layers.
Box 1: This is some
Box 2: Text with three
Box 3: Layers
If there are only one or two lines, the other boxes won't get any text and stay invisible.
I'm a bit rusty in terms of expressions, can anyone help me out?
I think one piece of code on the source text of each box should be sufficient, reading the text, splitting by line breaks and putting that into a string array. Box one pulls from {0}, Box 1 from {1} and Box from {2}.
Thank you!
Copy link to clipboard
Copied
If your text input is in a layer named "Text Input", then you could get each line with a source text expression like this:
txt = thisComp.layer("Text Input").text.sourceText;
lines = txt.split("\r");
lines[0]
where the last line determines which line of text you get.
Copy link to clipboard
Copied
Sweet, thanks! That does exactly what I need. Now I only need to solve the box height for ascenders and descenders 😂
Copy link to clipboard
Copied
This modification keeps the expression from breaking when the input text doesn't have enough lines for all the expressions (it just display a blank line):
txt = thisComp.layer("Text Input").text.sourceText;
lines = txt.split("\r");
idx = 0; // which line to get
idx > lines.length - 1 ? "" : lines[idx]
Copy link to clipboard
Copied
Can you explain where this would be neccessary? I've tried the first expression and it works without any errors, even with just one or two lines.
Copy link to clipboard
Copied
That's interesting. If you switch to the Legacy Extendscript expression engine, the expression will generate an error if it tries to retrieve a line that doesn't exist. Apparently the newer JavaScript engine that supresses that error. I wasn't aware of that. You learn something every day. In any case, I think it's good practice to defend against an array index running off the end of the array.
Copy link to clipboard
Copied
this has been asked before ( ascenders and descenders ), and solved, here are 2 links
https://creativecow.net/forums/thread/text-building-upwards-and-ignoring-descenders/
Copy link to clipboard
Copied
You have asked this about Expressions, but we have recently released in beta an ability in Scripting to set the box to auto fit based on the height of the text - so it does not go overset.
I am wondering if this might be something useful in your template building toolbox.
Rather than trying to split up the lines in this way, keeping them in the same box and adapting a shape to the size of the box?
At the moment the box only changes in height, and from the bottom, which might be an issue for you.
Though the API is not supported in Expressions, and it is not exposed in the UI, you can use Scripting to set the property on the box and it will still function even though an Expression is changing the content.
We think it will a powerful ability, but it is early days and we are eager to get some feedback from template builders such as yourself who might try to use. it.
Douglas Waterfall
After Effects Engineering