Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Word Count a book

Return to Member Forum

  • Author
    Posts
    • #56622

      Hi,

      do someone know a script or so to count all words of an indesign book.

      I'm thinking of a GREP search, but the method should be nice and understanding for a “non-indesign-pro”. And with a GREP search you can damage a lot, if you don't use it appropriate.

      If someone knows a script or a bullet proof method for a GREP search string, please let me know.

      Martin

    • #56723

      My solution for now is the following:

      GREP search:

      • search for: b.+?s (description: wordBoundary anyCharacter oneOrMoreTimes(ShortestFit) anySpaceCharacter)
      • change to: $0 (description: replaceWithFound)
      • search in: all documents (description: InDesign searches in all opened documents)

      IMPORTANT:

      • Save before searching and close your document after you have performed the search; so you will not save any corrupt files.
      • Watch out that you don't search and replace any formatting.
      • If you do something wrong (e.g. insert one different character) you can kill you document(s) – but you can undo the search with cmd+z.
    • #56725

      Counting words is a sort of Black Art: What is a Word?

      This script will open all of the documents in your book, count the words according to 2 different methods (I'm sure other scripters will find more ways), then display the results. Then choose which number to believe ;)

      //DESCRIPTION:Count Words Per Book
      // A Jongware Script 18-Aug-2010
      book = app.activeBook;
      words_a = 0;
      words_b = 0;

      for (var d=0; d<book.bookContents.length; d++)
      {
      doc = app.open (book.bookContents[d].fullName);
      words_a += countWords_a (doc);
      words_b += countWords_b (doc);
      doc.close(SaveOptions.NO);
      }
      alert (“Number of words: “+words_a+”rOr possibly: “+words_b);

      function countWords_a (aDoc)
      {
      var w = aDoc.stories.everyItem().words.length;
      return w;
      }

      function countWords_b (aDoc)
      {
      app.findGrepPreferences = null;
      app.findGrepPreferences.findWhat = “\w+”;
      var w = aDoc.findGrep().length;
      return w;
      }

    • #56728

      Wow, thats a lot more secure way, thanks.

      Is it possible to change the code to all current opened documents, and kick the book feature out.

      So you have the possibility to count the documents you want to.

    • #56729

      Sure. Change the loop from

      for (var d=0; d<book.bookContents.length; d++)
      {
      doc = app.open (book.bookContents[d].fullName);
      words_a += countWords_a (doc);
      words_b += countWords_b (doc);
      doc.close(SaveOptions.NO);
      }

      to

      for (var d=0; d<app.documents.length; d++)
      {
      doc = app.documents[d];
      words_a += countWords_a (doc);
      words_b += countWords_b (doc);
      }

    • #56730

      Yes, thats it. Thanks a lot!

      The final code:

      //DESCRIPTION:Count Words of Opened Documents

      // A Jongware Script 18-Aug-2010

      words_a = 0;

      words_b = 0;

      //loop

      for (var d=0; d<app.documents.length; d++)

      {

      doc = app.documents[d];

      words_a += countWords_a (doc);

      words_b += countWords_b (doc);

      }

      //alert message

      alert (“Number of words: “+words_a+”rOr possibly (by GREP): “+words_b);

      //word count function a

      function countWords_a (aDoc)

      {

      var w = aDoc.stories.everyItem().words.length;

      return w;

      }

      //word count function b

      function countWords_b (aDoc)

      {

      app.findGrepPreferences = null;

      app.findGrepPreferences.findWhat = “w+”;

      var w = aDoc.findGrep().length;

      return w;

      }

    • #63350
      hguhgu
      Member

      It works absolutely fine. Thank you very much. How would a script for counting charters in an open document look like :-)

      Henrik

Viewing 6 reply threads
  • You must be logged in to reply to this topic.
Forum Ads