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

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

Advocate ,
Oct 07, 2014 Oct 07, 2014

Copy link to clipboard

Copied

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

Views

1.7K

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

BEGINNER_X

Thank you very much

But the scrip Seems to be wrong

And it Prompts many script aqk

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Hi virender~

No any response

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

Oh my god ~~

I would to do it in Indesign Cs6

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