8 Replies Latest reply on Jul 26, 2014 2:24 AM by Teetan VK

    How Can I make book Contents by using script?

    Teetan VK Level 1

      Hi, everyone

       

      I assume a script can do this:

       

      When I open a indesign book, then run the script,

      I can get a pop up text file with a list of book contents, and page numbers

       

      for me to easily make a contents

       

      idean inspire by this link:

       

      How to write a script for report the page number in a book?

       

      thanks

       

      VK

        • 1. Re: How Can I make book Contents by using script?
          Chinnadk Level 4

          Hi VK,

           

          Try this,

           

          var book = app.activeBook,
              _content = "";
          for(var i =0;i<book.bookContents.length;i++)
          {
                  _content += book.bookContents[i].name + "\t" + book.bookContents[i].documentPageRange + "\r";
              }
          alert(_content);
          

           

          Regards,

          Chinna

          • 2. Re: How Can I make book Contents by using script?
            Teetan VK Level 1

            HI, Chinna

             

            thank you for your help

             

            Thank you, so much,

             

            but can it pop up in the note pad?

             

            aim to let me copy it.

             

            Regards

            VK

            • 3. Re: How Can I make book Contents by using script?
              Teetan VK Level 1

              Hi, Chinna

               

              I change it into this

               

              but got an error

               

              VK

              • 4. Re: How Can I make book Contents by using script?
                Teetan VK Level 1

                HI, Chinna

                 

                I don't want the .documentPageRange

                 

                I just want the start of page number, the first number of the each document

                 

                VK

                • 5. Re: How Can I make book Contents by using script?
                  Teetan VK Level 1

                  Hi Chinna

                   

                  I change it into this:

                   

                  //---------------------------------------------------------------------------------------- -------------------------------------------------------------------

                   

                  var book = app.activeBook, 

                      _content = ""; 

                  for(var i =0;i<book.bookContents.length;i++) 

                          _content += book.bookContents[i].name + "\t" + book.bookContents[i].documentPageRange + "\r"; 

                      } 

                  alert(_content);

                   

                      WriteToFile(txt);

                   

                  //---------------------------------------------------------------------------------------- ----------------------

                  function WriteToFile(text) {

                      file = new File("~/Desktop/Book contents with page number");

                      file.encoding = "UTF-8";

                      file.open("w");

                      file.write(text);

                      file.close();

                      file.execute();

                  }

                  //---------------------------------------------------------------------------------------- ----------------------

                   

                   

                  but error

                   

                  what's the syntax

                   

                  VK

                  • 6. Re: How Can I make book Contents by using script?
                    Teetan VK Level 1

                    Hi Chinna

                     

                    My idea inspire by this script:

                     

                    I wish you can find a clue from this script:

                     

                    //---------------------------------------------------------------------------------------- -------------------------------

                     

                    if (app.documents.length == 0) ErrorExit("Please open a document and try again.");

                     

                    const gScriptName = "List paragraph and character styles"; // Name of the script

                    const gScriptVersion = "1.0"; // Version

                    var gDoc = app.activeDocument;

                     

                    Main();

                     

                    //======================= FUNCTIONS  ============================

                    function Main() {

                        var ps, cs;

                        var txt = "Paragraph styles:\r#;Style name;Font name;Font size;Leading\r"

                        var parStyles = gDoc.allParagraphStyles;

                        for (var p = 0; p < parStyles.length; p++) {

                            ps = parStyles[p];

                            txt = txt + (p+1) + ";" + ps.name + ";" + ps.appliedFont.postscriptName + ";" + ps.pointSize + ";" + ((ps.leading == 1635019116) ? "Auto" : ps.leading) + "\r";

                        }

                        var charStyles = gDoc.allCharacterStyles;

                        txt = txt + "\rCharacter styles:\r#;Style name;Font name;Font style;Font size;Leading\r";

                        for (var c = 0; c < charStyles.length; c++) {

                            cs = charStyles[c];

                            txt = txt + (c+1) + ";" + cs.name + ";" + ((cs.appliedFont == "") ? "Not set" : cs.appliedFont)  + ";" + ((cs.fontStyle ==1851876449 ) ? "Not set" : cs.fontStyle)+ ";" + ((cs.pointSize == 1851876449) ? "Not set" : cs.pointSize) + ";" + ((cs.leading == 1851876449) ? "Not set" : cs.leading) + "\r";

                        }

                        WriteToFile(txt);

                    }

                    //---------------------------------------------------------------------------------------- ----------------------

                    function WriteToFile(text) {

                        file = new File("~/Desktop/Paragraph and character styles.csv");

                        file.encoding = "UTF-8";

                        file.open("w");

                        file.write(text);

                        file.close();

                        file.execute();

                    }

                    //---------------------------------------------------------------------------------------- ----------------------

                    function ErrorExit(error, icon) {

                        alert(error, gScriptName + " - " + gScriptVersion, icon);

                        exit();

                    }

                     

                    //---------------------------------------------------------------------------------------- --------------------------------

                     

                    Regards

                     

                    VK

                    • 7. Re: How Can I make book Contents by using script?
                      Sajeev Sridharan Level 4

                      I have modified slightly in your script,

                       

                      //---------------------------------------------------------------------------------------- -------------------------------------------------------------------

                       

                      var book = app.activeBook,

                          _content = "";

                      for(var i =0;i<book.bookContents.length;i++)

                      {

                          var startPage = book.bookContents[i].documentPageRange.split("-");

                              _content += book.bookContents[i].name + "\t" + startPage[0] + "\r";

                          }

                      //alert(_content);

                       

                          WriteToFile(_content);

                       

                      //---------------------------------------------------------------------------------------- ----------------------

                      function WriteToFile(text) {

                          file = new File("~/Desktop/Book contents with page number.txt");

                          file.encoding = "UTF-8";

                          file.open("w");

                          file.write(text);

                          file.close();

                          file.execute();

                      }

                      //---------------------------------------------------------------------------------------- ----------------------

                       

                       

                      Vandy

                      • 8. Re: How Can I make book Contents by using script?
                        Teetan VK Level 1

                        Thank you Vandy

                         

                        thank you very much,

                         

                        but I WANT TO give Chinna a correct answer, his was help me a lot

                         

                        I feel so sorry

                         

                        and thank you very much, appreciate

                         

                        VK