4 Replies Latest reply on Mar 15, 2008 9:32 PM by (Avi)

    About book

    Level 1
      I am trying to create a book using javascript

      var mybook = app.books.add(myPath + Save + ".indb");

      When you run above code it will work(it will create a book). Now i am trying to load a file in that book using following code

      mybook.bookContents.add(myPath + Save + "-TOC.indd");

      But when you try to run above code ,i am getting error as file dont find on that path. But when i give alert for that file name it will give that file name. It means that file is there but still it is showing file does not found.

      After that i need to save this book for that i am using

      app.books.save(File(myPath + Save + ".indb"), true);

      What is wrong in above code.

      I had posted same queery in my early post but i did not got satisfacotry answer.
      Please help me to solve this problem. I knew this forum have lots off expert people which can help me.

        • 1. Re: About book
          [Jongware] Most Valuable Participant
          >file dont find on that path

          Perhaps it's due to the difference between a File (which is an object) and your input (which is a text string). It has been mentioned somewhere before in this forum.

          >app.books.save(File(myPath + Save + ".indb"), true);

          A syntax error, or perhaps "doesn't support this method". app.books is an array; use mybook.save instead, which is equivalent to app.books[YourBookIndex].save.
          • 2. Re: About book
            Level 1
            Thank you for your reply.

            var mybook = app.books.add(myPath + Save + ".indb");
            mybook.save(File(myPath + Save + ".indb"), true);

            As per your suggestion i change app.book.save to mybook.save but still it is giving me error and error is

            "Invalid value for parameter 'versionComment'...'save'. Expected string, but recevied true"

            Do you know is there any other way to load the file into the book or to load a complete folder into the book. If i have a folder where i can save all indesign file. I want to load all the files into the book. Is there any way to do this.

            • 3. Re: About book
              [Jongware] Most Valuable Participant
              The error is because of

              >void save ([to: File][, versionComments: string][, forceSave: bool=false])

              Since you don't specify which arguments you set, it takes "versionComments" to be 'true', which causes the error.

              >mybook.save(File(myPath + Save + ".indb"), "", true);

              will do the trick. See the Scripting Help for more information on the arguments.
              You didn't say if 'loading the file into the book' worked or not, but there is only one way to do so. I guess you have to do

              >mybook.bookContents.add(File(myPath + Save + "-TOC.indd"));

              there as well (with "File" added).
              • 4. Re: About book
                Level 1
                Thank you jongware.

                Your trick works.
                Thank you.