Skip to main content
dublove
Legend
October 7, 2014
Question

Is there a script can count How many lines,and one line have how many words In a text box?

  • October 7, 2014
  • 1 reply
  • 2064 views

I have see there is a script for counting how many words in a document.

Also,Is there a script can count How many lines,and one line have how many words In a text box?

And they should be combined in a script.

Thank you~~

This topic has been closed for replies.

1 reply

BEGINNER_X
Legend
October 7, 2014

Hi ednly,

Is this is your requirement:

var myWords = app.activeDocument.stories.everyItem().words.everyItem().getElements();

alert("words in the document: " + myWords.length)

var myLines = app.activeDocument.stories.everyItem().lines.everyItem().getElements();

alert("lines in the document : " + myLines.length)

myCount = 0;

for(i=0; i<myLines.length; i++)

{

    myCount++

   

    var myWords = myLines.words.everyItem().getElements();

   

    alert("Line " + myCount + ": " + myWords.length + " words count")

   

    }

Regards

Siraj

dublove
dubloveAuthor
Legend
October 7, 2014

BEGINNER_X

Thank you very much

But the scrip Seems to be wrong

And it Prompts many script aqk

Inspiring
October 9, 2014

hi ednly,

the script by Siraj works perfectly. If you need to know the counts for one text box e.g. selected box then here is the script.

var myWords = app.activeDocument.stories.everyItem().words.everyItem().getElements(); 

$.writeln("total words in the document: " + myWords.length)  // you can replace $.writeln with alert if you want.

     var myDoc = app.activeDocument;

     var mytextFrame = myDoc.selection[0];

     if (myDoc.selection.length == 1)

          {

               var myLines = mytextFrame.lines              //.everyItem().getElements; 

               $.writeln("lines in the selected text frame are : " + myLines.length) 

               myCount = 0; 

               for(i=0; i<myLines.length; i++)      

                    { 

                        myCount++ 

                        var myWords = myLines.words.everyItem().getElements(); 

                        $.writeln ("Line " + myCount + ": " + myWords.length + " words count") 

                   } 

          }

else {

    alert ("No text frame is selected");

    }

virender