Activity › Forums › Adobe After Effects Expressions › Insert Line Break every X number of characters
-
Insert Line Break every X number of characters
Pete Menich replied 2 years ago 10 Members · 22 Replies
-
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.
Reply to this Discussion! Login or Sign Up