Copy link to clipboard
Copied
hello-
first time posting, be gentle. I'm playing around with good old sourceRectAtTime and while I can get the basics for what I need, I'm wondering if it would be possible to find the width of specific lines of text, between carriage returns? in other words, if I have one text layer that is multiple lines (potentially) but I want to have a shape behind each one that actually corresponds to the width of the specific line it is behind, is that possible? my alternative is of course to utilize multiple text layers but I'd rather be able to automate it so a user can input text with carriage returns and it is all straightforward that way.
any help would be great, thanks!
Long and short: Nope. sourceRectAtTime() is exactly that - a layers content bounding box, nothing more. there is no way to derive anything more from it because those values you would need simply don't exist in a form that would be accessibel to expressions. As it stands, your only option would be to do the calculations yourself using string operations and adding known widths of letters up.
Mylenium
Copy link to clipboard
Copied
Long and short: Nope. sourceRectAtTime() is exactly that - a layers content bounding box, nothing more. there is no way to derive anything more from it because those values you would need simply don't exist in a form that would be accessibel to expressions. As it stands, your only option would be to do the calculations yourself using string operations and adding known widths of letters up.
Mylenium
Copy link to clipboard
Copied
yeah, that's what i sorta figured. thanks for your help!
Copy link to clipboard
Copied
I figured this one out by using the Javascript "split" function to divide up the main SourceText property by carriage returns. You do have to use multiple text layers, but they can work in the background and the user can still just be given a single entry field.
Create as many additional text layers as you think you might have lines in an extreme scenario. Add an expression to the source text of each of those layers that's something like this:
textVal=thisComp.layer("Main User-Controlled Text Layer").text.sourceText;
linesVal=textVal.split("\r");
linesVal[0];
The key here is knowing that "\r" signifies a carriage return. With the text divided in that way, just grab a different piece of the resulting array on each layer. Then, wherever you're needing to identify the individual line widths, just reference those helper layers (i.e. "thisComp.layer("Line Width 1").sourceRectAtTime().width;")
Copy link to clipboard
Copied
This surely works, as long as you know user used only return carriages.
Make sure to check "shift+return" split case as well, which stands for: \x03
Other than that, there is also \n next line indicator, but it might be not used in AE's texts. These are three common next-line indicators from text editors.
Copy link to clipboard
Copied
Hello,
A bit late but I found a way to do this by cheating and I want to share it.
You use the split function and change the content of the text layer after the out point.
I explain :
##### code in text source #####
textVal = text.sourceText;
linesVal=textVal.split("\r");
for(i=0 ; i<linesVal.length ; i++){
if (time>=thisLayer.outPoint+i+1){
textVal = linesVal[i] }
}
textVal
##########
By this way I transform my text content each second after the out-point (so we'll never see that text) with the content of one line (the first line at 1 second after out point, the line 2 at 2 second after out point, etc.)
After that you just have to get the sourceRectAtTime width at the time corresponding to the line content :
##### code to get the width #####
thisComp.layer("mytextLayer").sourceRectAtTime(thisComp.layer("mytextLayer").outPoint+1,false).width;
Hope that could help somebody
Find more inspiration, events, and resources on the new Adobe Community
Explore Now