Skip to main content
Participant
November 3, 2023
Answered

Is there a way of recognising linebreaks with a Text Box

  • November 3, 2023
  • 1 reply
  • 316 views

Hi,

I am running Illustrator 28.0 on Mac OS 13.6.1.

I am currently flowing varied text in to a text box, and wondered if there was a way in which I could identify the linesbreaks within the text box. So I would want to be able to recognise once the text is flown in the words 'the_' and 'Sat_'. The reason for this is so I can potentially identify with coding and manipulate actions when a linebreak is created.

Thanks

Steve

This topic has been closed for replies.
Correct answer femkeblanco

This should output a list of words at line breaks (but not paragraph breaks).  A text frame should be selected.

var output = "";
var paragraphs = app.selection[0].paragraphs;
for (var i = 0; i < paragraphs.length; i++) {
    var lines = paragraphs[i].lines;
    for (var j = 0; j < lines.length - 1; j++) {
        var index = lines[j].words.length - 1;
        output += lines[j].words[index].contents + "\n";
    }
}
alert(output);

 

 

 

1 reply

femkeblanco
femkeblancoCorrect answer
Legend
November 3, 2023

This should output a list of words at line breaks (but not paragraph breaks).  A text frame should be selected.

var output = "";
var paragraphs = app.selection[0].paragraphs;
for (var i = 0; i < paragraphs.length; i++) {
    var lines = paragraphs[i].lines;
    for (var j = 0; j < lines.length - 1; j++) {
        var index = lines[j].words.length - 1;
        output += lines[j].words[index].contents + "\n";
    }
}
alert(output);

 

 

 

Participant
November 4, 2023

Thank you so much femkeblanco

That worked perfectly