• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Get all one-line paragraphs

Advisor ,
Sep 17, 2012 Sep 17, 2012

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?

TOPICS
Scripting

Views

671

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 17, 2012 Sep 17, 2012

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 17, 2012 Sep 17, 2012

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 17, 2012 Sep 17, 2012

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines