3 Replies Latest reply: Jul 28, 2012 8:54 AM by Marcos Suárez RSS

    Count words in a book of InDesign CS4

    Marcos Suárez

      With this script we can count the words, paragraphs and footnotes in a document indesign ...

      But I need to make this count in a book of InDesign ...

      Any ideas?

       

       

      var docWordCount = app.activeDocument.stories.everyItem().words.length; // words
      var docParCount = app.activeDocument.stories.everyItem().paragraphs.length; // paragraphs
      var docNoteWordCount = app.activeDocument.stories.everyItem().footnotes.everyItem().words.length; // words in footnotes
      var docNotesCount = app.activeDocument.stories.everyItem().footnotes.length; // footnotes
      
      // TABLAS *************************************************************************************************************************
      var docTableWordCount = 0;
      if (app.activeDocument.stories.everyItem().tables.length)
          {
              docTableWordCount = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().words.length;
          }
      
      // ***********************************************************************************************************************************************************************
      var myDocWordCount = docWordCount + docNoteWordCount + docTableWordCount;
      alert("Tienes " + myDocWordCount + " palabras, " + docParCount + " párrafos y "+ docNotesCount + " notas en el documento. Ojo, también se incluyen págs. maestras, pero no sus textos repetidos en maqueta   ", "RECUENTO DE PALABRAS, NOTAS Y PÁRRAFOS (MSP)");
      
        • 1. Re: Count words in a book of InDesign CS4
          Harbs. CommunityMVP

          Try this:

          var docWordCount = app.books[0].documents.everyItem().stories.everyItem().words.length; // words
          var docParCount = app.books[0].documents.everyItem().stories.everyItem().paragraphs.length; // paragraphs
          var docNoteWordCount = app.books[0].documents.everyItem().stories.everyItem().footnotes.everyItem().words.length; // words in footnotes
          var docNotesCount = app.books[0].documents.everyItem().stories.everyItem().footnotes.length; // footnotes
          
          // TABLAS *************************************************************************************************************************
          var docTableWordCount = 0;
          if (app.books[0].documents.everyItem().stories.everyItem().tables.length)
              {
                  docTableWordCount = app.books[0].documents.everyItem().stories.everyItem().tables.everyItem().cells.everyItem().words.length;
              }
          
          // ***********************************************************************************************************************************************************************
          var myDocWordCount = docWordCount + docNoteWordCount + docTableWordCount;
          alert("Tienes " + myDocWordCount + " palabras, " + docParCount + " párrafos y "+ docNotesCount + " notas en el documento. Ojo, también se incluyen págs. maestras, pero no sus textos repetidos en maqueta   ", "RECUENTO DE PALABRAS, NOTAS Y PÁRRAFOS (MSP)");
          
          • 2. Re: Count words in a book of InDesign CS4
            Harbs. CommunityMVP

            That should have been app.books[0].bookContents.everyItem() instead of app.books[0].documents.everyItem()...

            • 3. Re: Count words in a book of InDesign CS4
              Marcos Suárez Community Member

              Harbs, your code did not work ...

              But I got something like what I wanted: to make a count of all open documents ...

               

              // RECUENTO DE PALABRAS, NOTAS Y PÁRRAFOS EN DOCUMENTOS ABIERTOS ************************************************************/

              var DOCS = app.documents.length;

              var docWordCount = app.documents.everyItem().stories.everyItem().words.length; // words

              var docParCount = app.documents.everyItem().stories.everyItem().paragraphs.length; // paragraphs

              var docNoteWordCount = app.documents.everyItem().stories.everyItem().footnotes.everyItem().words.length; // words in footnotes

              var docNotesCount = app.documents.everyItem().stories.everyItem().footnotes.length; // footnotes

              // TABLAS ***************************************************************************************** ****************************************************

              var docTableWordCount = 0;

              if (app.documents.everyItem().stories.everyItem().tables.length)

                  {

                      docTableWordCount = app.documents.everyItem().stories.everyItem().tables.everyItem().cells.everyItem().words. length;

                  }

              // ***************************************************************************************** ******************************************************************************

              var myDocWordCount = docWordCount + docNoteWordCount + docTableWordCount;

              alert("En " + DOCS + " documento(s) tienes " + myDocWordCount + " palabras, " + docParCount + " párrafos y "+ docNotesCount + " notas. Ojo, también se incluyen págs. maestras, pero no sus textos repetidos en maqueta   ", "RECUENTO DE PALABRAS, NOTAS Y PÁRRAFOS (MSP)");