3 Replies Latest reply on Sep 17, 2012 7:49 AM by Peter Kahrel

    Get all one-line paragraphs

    Vamitul Level 4


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

        • 1. Re: Get all one-line paragraphs
          Peter Kahrel Adobe Community Professional & MVP

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



          • 2. Re: Get all one-line paragraphs
            Laubender Adobe Community Professional & MVP

            @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.




            • 3. Re: Get all one-line paragraphs
              Peter Kahrel Adobe Community Professional & MVP



              Thats because these two are the same:





              Looping is indeed the way to go.