From: "=?utf-8?Q?Mathias_M=C3=B6hl?=" Received: from mail-wm0-f51.google.com ([74.125.82.51] verified) by media-motion.tv (CommuniGate Pro SMTP 6.1.0) with ESMTPS id 6434139 for AE-List@media-motion.tv; Wed, 11 Apr 2018 10:02:54 +0200 Received: by mail-wm0-f51.google.com with SMTP id u189so2229272wmd.1 for ; Wed, 11 Apr 2018 01:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:message-id:mime-version:subject:date:references:to:in-reply-to; bh=TG947uDnJ/elCMELuLt+SUrZpAaEgXZ8WgCs4lk5g9U=; b=s8Hi7w5oD7hZ2M9S03yJurXik69SVYKzyELsNcZwC/dh4BiouqRY1a5C15wDBBDqIr OuP1mHPCnlNslBXeDxUyMFGQWGqCL/nIRMI8gQPB1hUmXWGrmMO69y9E8PsRZC8g4aSV 3/Lba0cVAGowq+lNmoo3SGLlPoH5e3WOWvdeYXDaf9WDIs/Ax4OtSeTafu0NHSvrtZzF o0aELYuas4qz3JgLOy1ovH1Wt4SK1/kPINiuUdfPaXfz+qWrAsbYnqogkykomBQEIgb9 dnCf/z3UAGrCVgS4vMeJh9pXKVVTJGjfgprtL6yzT7SD8BMH2mmmEaI7KkbqrOnBsGK5 EueA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :references:to:in-reply-to; bh=TG947uDnJ/elCMELuLt+SUrZpAaEgXZ8WgCs4lk5g9U=; b=ZKDlCdY+D9xo8gZasA72oezokQxy2uX+tSmNXu6157ykX6OPYR/ZiR5FxhPTtSuXGI jNnwINgxMtqD2qWIpKUIueWMYYwJImOpyfPCugkAeXiy7P+16duGGe3/Ycx9ka3Ud3yr 13786q++FcdiVaRuxEAdu/aHNJxFwGgTC8p8lYsy8sPQEgMbihPPoGBGQp6MuKOGbKmI BXE+aL8WNN07vSfJs0zl9Tuaq5pQpQBqPrYF1EluRTNXJ7ONsW0uIrkp8Wd4nae+JVNL rs+3V0HfNEdWQP/5UEJyqVWa5u23J+mTJPmVW5ftILU+GStzeAoA0YWeqd6t6vWt4POE S6Nw== X-Gm-Message-State: ALQs6tC88qqiE4Uns1PqvD9h3g2HP9EoBIuaea2NH86xIIvXceqi2FtV rWNKKzv5fdhgt7ItMEjsBHpwZSD8 X-Google-Smtp-Source: AIpwx48S46sNn+MNktqui3xgjeF8X50QZtD99noReCwWmi/UH6dGOpj8tXBBvAgdEGTmo+7LaxFJTQ== X-Received: by 10.28.0.72 with SMTP id 69mr1660766wma.105.1523434094994; Wed, 11 Apr 2018 01:08:14 -0700 (PDT) Return-Path: Received: from mathiasmac-3.fritz.box (p3EE094B0.dip0.t-ipconnect.de. [62.224.148.176]) by smtp.googlemail.com with ESMTPSA id g75sm1124329wmc.47.2018.04.11.01.08.13 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Apr 2018 01:08:13 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_BF786A45-C226-485B-99FC-5D4434FDFBB5" Message-Id: <62EA2306-E31C-4231-AA02-5B93AE9023F2@googlemail.com> Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: [AE] Expression to break text after a certain number of characters Date: Wed, 11 Apr 2018 10:08:12 +0200 References: To: After Effects Mail List In-Reply-To: X-Mailer: Apple Mail (2.3124) --Apple-Mail=_BF786A45-C226-485B-99FC-5D4434FDFBB5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 You can split the text at linebreaks and then apply dan=E2=80=99s = processing to each of the parts separately: =E2=80=94=E2=80=94=E2=80=94=E2=80=94 txt =3D thisComp.layer("Source Text").text.sourceText; n =3D thisComp.layer("Controls").effect("Text width")("Slider"); function breakToGivenLength(txt,n){ var outStr =3D ""; var newLine =3D "" var splt =3D txt.split(" ") for (var i =3D 0; i < splt.length; i++){ if ((newLine + " " + splt[i]).length > n){ if (outStr !=3D "") outStr +=3D "\r"; outStr +=3D newLine; newLine =3D splt[i]; }else{ if (newLine !=3D "") newLine +=3D " "; newLine +=3D splt[i]; } } if (newLine !=3D ""){ if (outStr !=3D "") outStr +=3D "\r"; outStr +=3D newLine; } return outStr; } lines =3D txt.split(/|\r|\n|\x03/); for(var i=3D0; i< lines.length; i++){ lines[i]=3DbreakToGivenLength(lines[i],n); } lines.join("\n"); =E2=80=94=E2=80=94=E2=80=94=E2=80=94 Note that this still does not deal properly at tabs, for example (it = only breaks at simple line breaks but not at tabs). Cheers, Mathias mamoworld.com simplify your cgi Dr. Mathias M=C3=B6hl Marlow 52 , 18551 Sagard, Germany Phone +49 (0)38302 - 88 75 61 info@mamoworld.com > On 11 Apr 2018, at 09:33, Jarle Leirpoll = wrote: >=20 > I found this expression from Dan Ebberts, and it works beautifully = until the > source text has line breaks. > After the line breaks, the first lines get shorter. It seems to add = the > characters from the line above the break to the character count. See = this > image: > https://www.dropbox.com/s/a842o913cxhyeua/LineBreakTrouble.png?dl=3D0=20= >=20 > Is there a way to make this code aware of line breaks too, so that it = just > keeps the line breaks from the source and starts on a new line with = the > correct length? >=20 > The goal is that the user should just copy-paste text from a word = document > or similar, into a field - and it should just work. >=20 > /jarle >=20 > txt =3D thisComp.layer("Source Text").text.sourceText; > n =3D thisComp.layer("Controls").effect("Text width")("Slider"); > outStr =3D ""; > newLine =3D "" > splt =3D txt.split(" ") > for (i =3D 0; i < splt.length; i++){ > if ((newLine + " " + splt[i]).length > n){ > if (outStr !=3D "") outStr +=3D "\r"; > outStr +=3D newLine; > newLine =3D splt[i]; > }else{ > if (newLine !=3D "") newLine +=3D " "; > newLine +=3D splt[i]; > } > } > if (newLine !=3D ""){ > if (outStr !=3D "") outStr +=3D "\r"; > outStr +=3D newLine; > } > outStr; >=20 >=20 >=20 >=20 > +---End of message---+ > To unsubscribe send any message to --Apple-Mail=_BF786A45-C226-485B-99FC-5D4434FDFBB5 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 You can split the text at linebreaks and then apply dan=E2=80=99= s processing to each of the parts separately:

=E2=80=94=E2=80=94=E2=80=94=E2=80=94

txt = =3D thisComp.layer("Source Text").text.sourceText;
n = =3D thisComp.layer("Controls").effect("Text width")("Slider");

function = breakToGivenLength(txt,n){
  var outStr =3D = "";
  var newLine =3D ""
  var splt =3D txt.split(" ")
  = for (var i =3D 0; i < splt.length; i++){
  =   if ((newLine + " " + splt[i]).length > n){
      if (outStr !=3D "") outStr +=3D = "\r";
      outStr +=3D = newLine;
      newLine =3D = splt[i];
    }else{
      if (newLine !=3D "") newLine +=3D " = ";
      newLine +=3D = splt[i];
    }
  = }
  if (newLine !=3D ""){
    if (outStr !=3D "") outStr +=3D "\r";
    outStr +=3D newLine;
  = }
  return outStr;
}

lines =3D = txt.split(/|\r|\n|\x03/);
for(var i=3D0; i< = lines.length; i++){
  = lines[i]=3DbreakToGivenLength(lines[i],n);
}
lines.join("\n");


=E2=80=94=E2=80=94=E2=80=94=E2=80=94

Note that this still does not deal = properly at tabs, for example (it only breaks at simple line breaks but = not at tabs).

Cheers,
Mathias



mamoworld.com
simplify your cgi

Dr. Mathias M=C3=B6hl
Marlow 52 , 18551 Sagard, Germany
Phone +49 = (0)38302 - 88 75 61
info@mamoworld.com


<= /div>

On = 11 Apr 2018, at 09:33, Jarle Leirpoll <AE-List@media-motion.tv> wrote:

I = found this expression from Dan Ebberts, and it works beautifully until = the
source text has line breaks.
After the = line breaks, the first lines get shorter. It seems to add the
characters from the line above the break to the character = count. See this
image:
https://www.dropbox.com/s/a842o913cxhyeua/LineBreakTrouble.png?= dl=3D0

Is there a way to make this = code aware of line breaks too, so that it just
keeps the = line breaks from the source and starts on a new line with the
correct length?

The goal is that = the user should just copy-paste text from a word document
or= similar, into a field - and it should just work.

/jarle

txt =3D = thisComp.layer("Source Text").text.sourceText;
n =3D = thisComp.layer("Controls").effect("Text width")("Slider");
outStr =3D "";
newLine =3D ""
splt = =3D txt.split(" ")
for (i =3D 0; i < splt.length; = i++){
 if ((newLine + " " + splt[i]).length > = n){
   if (outStr !=3D "") outStr +=3D = "\r";
   outStr +=3D newLine;
=    newLine =3D splt[i];
 }else{
   if (newLine !=3D "") newLine +=3D " ";
   newLine +=3D splt[i];
=  }
}
if (newLine !=3D ""){
=  if (outStr !=3D "") outStr +=3D "\r";
 outStr = +=3D newLine;
}
outStr;




+---End of = message---+
To unsubscribe send any message to <ae-list-off@media-motion.tv>




= --Apple-Mail=_BF786A45-C226-485B-99FC-5D4434FDFBB5--