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

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

Guide ,
Oct 07, 2014 Oct 07, 2014

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~~

TOPICS
Scripting
2.0K
Translate
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
Enthusiast ,
Oct 07, 2014 Oct 07, 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

Translate
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
Guide ,
Oct 07, 2014 Oct 07, 2014

BEGINNER_X

Thank you very much

But the scrip Seems to be wrong

And it Prompts many script aqk

Translate
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
Engaged ,
Oct 09, 2014 Oct 09, 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

Translate
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
Guide ,
Oct 09, 2014 Oct 09, 2014

Hi virender~

No any response

Translate
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
Engaged ,
Oct 09, 2014 Oct 09, 2014

hi edny,

the count will appear at Window => "Javascript console", once you run script.

Otherwise $.writeln with alert in script to see as alert.

virender

Translate
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
Guide ,
Oct 09, 2014 Oct 09, 2014
LATEST

Oh my god ~~

I would to do it in Indesign Cs6

Translate
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