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

JSX for word count, including tables

New Here ,
Nov 08, 2010 Nov 08, 2010

Copy link to clipboard

Copied

Hi folks,

I've tried two different scripts (found on this site) to attempt to get the word count out of an entire book, including all stories, tables, and captions.

The first:

alert("There are "+ app.documents[0].stories.everyItem().words.length +" words in the active document.")

Then this one, which doesn't count numbers and symbols, which I like:

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = "[\\u\\l][-\\u\\l]+";

found = app.documents[0].findGrep ();

alert ("There are " + found.length + " words in this document.")

The difficulty is that neither of them include words in tables. Is there a way to force this in this script?

TOPICS
Scripting

Views

1.4K

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 ,
Nov 10, 2010 Nov 10, 2010

Copy link to clipboard

Copied

// First do a word count in the main text (as before)

found = app.documents[0].findGrep ().length;

// Then find every word in every table in every story

t = app.documents[0].stories.everyItem().tables.everyItem().findGrep();

// "t" is an array of arrays, now you need to add the length of each array to "found"


for (i = 0; i < t.length; i++)
   found += t.length;

alert ("There are " + found + " words in this document.")

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
New Here ,
Nov 10, 2010 Nov 10, 2010

Copy link to clipboard

Copied

As written, it threw an error. When I added script from one of my other ones, it did, but I am still not getting the correct answer. It now looks like this.

// First do a word count in the main text (as before)


app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = "[\\u\\l][-\\u\\l]+";

found = app.documents[0].findGrep ().length;

// Then find every word in every table in every story

t = app.documents[0].stories.everyItem().tables.everyItem().findGrep();

// "t" is an array of arrays, now you need to add the length of each array to "found"


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

   found += t.length;

alert ("There are " + found + " words in this document.")

It somehow manages to give a word count lower than the one which skips tables, and is over 1000 less than our "official" count from our translation company.

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 ,
Nov 10, 2010 Nov 10, 2010

Copy link to clipboard

Copied

>It somehow manages to give a word count lower than the one which skips tables

That's bizarre. It doesn't do any subtractions, so how the total can be lower if you include tavles is beyond me.

>and is over 1000 less than our "official" count from our translation company.

What does "official count" mean?

Petr

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
New Here ,
Nov 10, 2010 Nov 10, 2010

Copy link to clipboard

Copied

It is strange. All I can guess is that there is somehow some hidden text in the document that the translation company's software is seeing. Is that a possibility with INDD files?

And it's a good question what "official" means. I'll have to ask our translation dept what the vendor is using to get that word count. I hope they haven't been shafting us all along...

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
New Here ,
Jun 24, 2011 Jun 24, 2011

Copy link to clipboard

Copied

Did you ever successfully find a way to count all of the words in a book, including captions, TOC, etc.? Is there a software now that does this? I can't even find TextCount.js.

I have inDesign CS3.

Thank you so much!

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
People's Champ ,
Jun 26, 2011 Jun 26, 2011

Copy link to clipboard

Copied

To me it seems that the premise in the OP is wrong. The GREP script does count words in tables.

Thanks,

Ariel

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
Guest
Jun 27, 2011 Jun 27, 2011

Copy link to clipboard

Copied

LATEST

Hi,

You can try the following link for counting words including table:

http://indisnip.wordpress.com/2010/12/28/quicktip-counting-text-using-everyitem/

Regards

Peru.

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