Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Insert Line Break every X number of characters

  • Thomas Frenkel

    November 21, 2022 at 3:09 pm

    I 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 pm

    Yeah 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.

Page 3 of 3

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy