Truncate with Ellipsis

Caps text at a maximum length and adds an ellipsis, so long names can never break your layout.

Expression Code
// Truncate with Ellipsis
// Apply to Source Text
maxChars = 24; // Longest allowed text
ellipsis = "..."; // Trailing characters
wholeWords = 1; // 1 = never cut mid-word, 0 = hard cut
txt = String(value);
out = txt;
if (txt.length > maxChars) {
cut = txt.substring(0, maxChars);
if (wholeWords == 1) {
sp = cut.lastIndexOf(" ");
if (sp > 0) cut = cut.substring(0, sp);
}
out = cut + ellipsis;
}
out;
Apply to the Source Text of the editable text layer. The editor types whatever they like — in the comp or through Essential Graphics — and anything past maxChars is trimmed with an ellipsis. Text at or under the limit passes through untouched.
Back to Text & Numbers