Forums › Adobe After Effects Expressions › Insert Line Break every X number of characters
-
Insert Line Break every X number of characters
-
Filip Vandueren
November 21, 2022 at 1:39 pmThe “bound paragraph” methos should still work if the text’s driven by markers.
I think you’ll only need to change the first line of the sourceText parameter.But to be clear: that’s only if you absolutely need dynamic (moving) margins/width and reflowing.
For subtitles, why not use a regular box-text and let that do the wrapping ?
-
Thomas Frenkel
November 21, 2022 at 3:09 pmI never responded with the solution to my question. If you want the expression to respect manually input line breaks you need a second loop wrapped around like this:
txt=value;
lineLength=50;
finStr = "";
splt1=txt.split("\r");
for(n = 0; n < splt1.length; n++){
outStr = "";
newLine = "";
splt2 = splt1[n].split(" ");
for (i = 0; i < splt2.length; i++)
{
if ((newLine + " " + splt2[i]).length > lineLength){
if (outStr != "") outStr += "\r";
outStr += newLine;
newLine = splt2[i];
}else{
if (newLine != "") newLine += " ";
newLine += splt2[i];
}
}
if (newLine != ""){
if (outStr != "") outStr += "\r";
outStr += newLine;
}
finStr+=outStr+"\r";
}
finStr; -
Pete Menich
November 21, 2022 at 3:21 pmYeah I got it working in the end with…
m = thisComp.layer("Captions");
n=0;
fs = text.sourceText.style.fontSize * 1000/effect("boxWidth")("Slider");
if (m.marker.numKeys > 0){
n = m.marker.nearestKey(time).index;
if (m.marker.key(n).time > time) n--;
}
if (n > 0)
{text.sourceText.createStyle().setFontSize(fs).setText(m.marker.key(n).comment);
}else{
text.sourceText.createStyle().setFontSize(fs).setText("");
}I’m just goofing around making a flexible subs generator.
Log in to reply.