Skip to main content
Vamitul
Legend
September 17, 2012
Question

Get all one-line paragraphs

  • September 17, 2012
  • 1 reply
  • 711 views

Hello!

Is there a faster way to find all one line paragraphs than iterating throug every story and every paragraph in it?

This topic has been closed for replies.

1 reply

Peter Kahrel
Community Expert
Community Expert
September 17, 2012

You need something like "if (myParagraph.lines.length == 1)", so the answer to your question is 'No, there is not.'

Peter

Community Expert
September 17, 2012

@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

Peter Kahrel
Community Expert
Community Expert
September 17, 2012

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