Thanks for this! I am having one issues though.
I am using a reference to text from a CSV file, the comp.name chooses the row from the CSV. It works perfectly on everything, except when the char_count is less than the char_per_line i.e when there should only be a single line of text.
When this is the case, the expression returns an error saying ‘property of methods named ‘i’ in class ‘global’ is missing or does not exist’.
Had a fiddle, but can’t seem to figure this out.
var compIndex = thisComp.name.split(" - ")[0];
txt = footage("TOVDataTest.csv").dataValue([1,compIndex]);
char_count = txt.length;
char_per_line = Math.ceil(thisComp.layer("Controllers").effect("Characters per line")("Slider"));
lines = Math.ceil(char_count/(char_per_line));
done = 0;
esc = 0;
len =0;
row = char_per_line;
while (done == 0){
esc ++;
len+=row;
if (txt.length >= len+1){
for (i = len; i > len-row; i--) if (txt[i] == " ") break;
if (i > len-row){
txt=txt.substr(0,i) + "\r" + txt.substr(i+1,9999);
}
}
len = i;
if (esc>100){done=1}
}
txt