5 Replies Latest reply on Jan 10, 2011 11:41 AM by Kasyan Servetsky

    How to create a Book in Indesign and add indesign documents to it?

      Hi all,

      Can I create a book in InDesign CS3 and add indesign documents to it using javascript.

      Thanks,
      Hemachandiran.
        • 1. Re: How to create a Book in Indesign and add indesign documents to it?
          Martin Fischer Level 2
          Hi K.

          yes, you can.

          Takt a look at this pretty old piece of code:


          // bookOfSelectedFolder.jsx
          //DESCRIPTION: Create a book and add indd-files of a choosen folder

          var myFolder = Folder.selectDialog( "Choose a folder" );
          if( myFolder != null ){
             // get indd-files of choosen folder
             var myFiles=myFolder.getFiles( "*.indd" );
             if ( myFiles.length > 0 ){
                var myBookFileName = myFolder + "/"+ myFolder.name + ".indb";
                myBookFile = new File( myBookFileName );
                try{
                   //does the book file exist?
                   myBook=app.open( myBookFile );
                }
                catch ( e ){
                   //the book file doesn't exist, so make a new one          
                   myBook=app.books.add( myBookFile );
                   myBook.automaticPagination=false;
                   for ( i=0; i < myFiles.length; i++ ){
                      myBook.bookContents.add( myFiles[i] );
                   }
                   myBook.save( );
                }
             }
          }


          Martin
          1 person found this helpful
          • 2. Re: How to create a Book in Indesign and add indesign documents to it?
            Level 1
            Its really useful martin.

            Thanks.

            I have another doubt, can i export the text frame contents to an RTF format using cs3. (using javascript)
            • 3. Re: How to create a Book in Indesign and add indesign documents to it?
              Martin Fischer Level 2
              Hi K.

              you may look for an object called textFrame in the DOM (e.g. in ESTK) and find out the methods of it. There you might find something called exportFile() and it's parameters.

              Martin
              • 4. Re: How to create a Book in Indesign and add indesign documents to it?
                shr_158

                Hi.

                 

                This script was fantastic through CS3, but now in CS4, it crashes the application. When I use the debugger in the ESTK, it crashes around this line:

                 

                myBook=app.open( myBookFile );

                 

                Does anyone know what the difference is in CS3 and 4 that is causing the error? I'm still learning how to script and have not been able to figure it out myself.

                 

                Thanks in advance.

                • 5. Re: How to create a Book in Indesign and add indesign documents to it?
                  Kasyan Servetsky Level 5

                  Here's my version of the script — now works in CS4 — may be it would come in handy to somebody:

                  var myFolder = Folder.selectDialog( "Select a folder with InDesign files" );
                  if ( myFolder != null ) {
                       var myFiles = [];
                       var myAllFilesList = myFolder.getFiles();
                  
                       for (var f = 0; f < myAllFilesList.length; f++) {
                            var myFile = myAllFilesList[f];
                            if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
                                 myFiles.push(myFile);
                            }
                       }
                       
                       if ( myFiles.length > 0 ) {
                            var myBookFileName = myFolder + "/"+ myFolder.name + ".indb";
                            myBookFile = new File( myBookFileName );
                            if ( myBookFile.exists ) {
                                 if ( app.books.item(myFolder.displayName + ".indb") == null ) {
                                      myBook = app.open( myBookFile );
                                 }
                            }
                            else {
                                  myBook = app.books.add( myBookFile );
                                  myBook.automaticPagination = false;
                                  for ( i=0; i < myFiles.length; i++ ) {
                                      myBook.bookContents.add( myFiles[i] );
                                  }
                                  myBook.save( );
                             }
                       }
                  }
                  
                  1 person found this helpful