Copy link to clipboard
Copied
Hello!
Is there a faster way to find all one line paragraphs than iterating throug every story and every paragraph in it?
Copy link to clipboard
Copied
You need something like "if (myParagraph.lines.length == 1)", so the answer to your question is 'No, there is not.'
Peter
Copy link to clipboard
Copied
@Peter – initially I thought something like this could give us an array of all line lengths of all paragraphs of all stories:
var myLength = app.activeDocument.stories.everyItem().paragraph.everyItem().lines.everyItem().length;
But that would give us an array of the counts of every character in every paragraph!
I guess it's because of a missing paragraph property that returns the line length.
Paragraphs should have the property "lineLength" or something equal.
If you look at the following snippet that detects the line length of a specific paragraph:
var myLength = app.activeDocument.stories[0].paragraphs[0].lines.length;
"myLength" is the value we are looking for.
But we cannot put that to wider use writing:
var myLength = app.activeDocument.stories[0].paragraphs.everyItem().lines.length;
The result would be the overall length of all lines of the story.
So in this case looping over all paragraphs of all stories is the thing we have to do, if we want to get the ones with only one line.
Uwe
Copy link to clipboard
Copied
Uwe,
Thats because these two are the same:
app.documents[0].stories[0].paragraphs.everyItem().lines.length
app.documents[0].stories[0].lines.length
Looping is indeed the way to go.
Peter