5 Replies Latest reply on Jan 21, 2013 10:31 PM by csm_phil

    Doubt in Book (.indb)

    BEGINNER_X Level 3

      Hi All,

       

       

      Requirement:

       

      How can we use book concept (.indb). Actually i have script for override all master page item in the active Document only.

       

      But I want to override all the BookContents in the active Book(.indb) (i.e., folio1.indd, folio2.indd, folio3.indd, folio4.indd, folio5.indd) see attachment.

       

       

      Here is trying code:

       

      For the single document only (working good):

       

       

      var myDocument = app.activeDocument

       

      var myPages = myDocument.pages;

       

      for(i=0; i < myPages.length; i++) {

           OverrideMasterItems();

           }

       

      function OverrideMasterItems() {

        var allItems = myDocument.pages[i].appliedMaster.pageItems.everyItem().getElements();

        for(var j=0;j<allItems.length;j++){

          try{allItems[j].override(myDocument.pages[i])}

          catch(e){}

        }

      }

       

       

       

      But my requirement is override all master page item through book(.indb)

       

       

      Trying code is (not working):

       

       

      //Over writing the master page elements through Book(.indb)

       

       

      var myBook = app.books[0]

       

      var myBookContents =app.books[0].bookContents.everyItem().getElements()

       

      var myPages = myBookContents.pages;

       

      for(i=0; i < myPages.length; i++) {

           OverrideMasterItems();

           }

       

      function OverrideMasterItems() {

        var allItems = myBook.pages[i].appliedMaster.pageItems.everyItem().getElements();

        for(var j=0;j<allItems.length;j++){

          try{allItems[j].override(myBook.pages[i])}

          catch(e){}

        }

      }

       

       

      I am the beginner. Book Concept is entirely new for me. Please anyone give solution.

       

      For Reference kindly see the attachment

       

      Screen Shot 2013-01-21 at 1.27.16 PM.png

       

      Thanks in advance

      BEGINNER_X

        • 1. Re: Doubt in Book (.indb)
          -hans- Level 4

          Hi,

           

          have a look at your variable

          var myBookContents =app.books[0].bookContents.everyItem().getElements()

          You'll see it's a array.

          so

          var currBookContent = myBookContents[0]

          will give infos to a item bookContent.

          currBookContent.fullName will return a fileobject to the corresponding document.

          Check if the document is already open, if not open it,  ... do stuff

           

           

          Hope it'll help ...

           

          Hans-Gerd Claßen

          • 2. Re: Doubt in Book (.indb)
            BEGINNER_X Level 3

            Hi Hans/All,

             

            Thanks for your reply....

             

            Using forum i got a script for open and close all the book contents. Its works fine.

             

            Code is below (working good):

             

             

            //Open all the Book Contents in the book

             

            for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i--)

            {

            app.open (app.activeBook.bookContents[i].fullName, true)

            }

             

            ////Close all the Book Contents in the book

             

            for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )

            {

                        app.open (app.activeBook.bookContents[i].fullName, false).close(SaveOptions.ASK);

                        }

             

             

            But as per my requirement i want to open all the documents(bookContents) in the book, override all master page elements and close all the documents in the book

             

             

            Trying Script is:

            for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )

            {

                        app.open (app.activeBook.bookContents[i].fullName, true)

                        bookOverrideMasterItems ()

                        app.open (app.activeBook.bookContents[i].fullName, false).close(SaveOptions.ASK);

                        }

             

            function bookOverrideMasterItems()

            {

                var myDocument = app.open (app.activeBook.bookContents[i].fullName, true);

                var myPages = myDocument.pages;

                for(i=0; i < myPages.length; i++) {

                 OverrideMasterItems();

                 }

             

            function OverrideMasterItems() {

              var allItems = myDocument.pages[i].appliedMaster.pageItems.everyItem().getElements();

              for(var j=0;j<allItems.length;j++){

                try{

                   

                    allItems[j].override(myDocument.pages[i]);

                   }

                catch(e){}

              }

            }

            }

             

            Please find the screenshot of error and my book(.indb)

             

             

            Screen Shot 2013-01-22 at 10.18.58 AM.png

            Screen Shot 2013-01-22 at 10.19.06 AM.png

            • 3. Re: Doubt in Book (.indb)
              csm_phil Level 4

              Hello BEGGINER_X,

               

              Try the below JS code, try to analyze the code! you just copy and paste the code its workigng, but sometime you defintely lock. try to analyze!

               

              for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )

              {

                  app.open (app.activeBook.bookContents[i].fullName, true)

                  bookOverrideMasterItems ()

                  }

               

               

               

              function bookOverrideMasterItems()

              {

                  var myDocument = app.open (app.activeBook.bookContents[i].fullName, true);

                  var myPages = myDocument.pages;

                  for(i=0; i < myPages.length; i++) {

                        var allItems = myDocument.pages[i].appliedMaster.pageItems.everyItem().getElements() ;

                        for(var j=0;j<allItems.length;j++){

                          try{

                              allItems[j].override(myDocument.pages[i]);

                             }

                          catch(e){}

                        }

                   }

                  myDocument.close(SaveOptions.YES)

                  // your below line asking the user to every document to save or close. In my above line save the document without user knowledge. which is best you can use it.

                  //myDocument.close(SaveOptions.ASK)

              }

               

               

              thx,

              csm_phil

              1 person found this helpful
              • 4. Re: Doubt in Book (.indb)
                BEGINNER_X Level 3

                Hi csm_phil,

                 

                 

                Thanks for your immediate reponse...

                 

                Problem is using the same variable throught the script. I think thats why the problem occur.

                 

                Now i change the variable name in Book Contents ('i' change into 'm'). Its working fine. Open and close all the book documents.

                 

                 

                Again Thanks a lot for you, Hans and ALL.

                 

                 

                Thanks

                Beginner

                • 5. Re: Doubt in Book (.indb)
                  csm_phil Level 4

                  Hello BEGGINER_X,

                   

                  You always keep in mind, to select the choice of quesetions is "Answered" or "Helpfull Answer", otherwise the thread is still open, please this is important all the user, because the people go and watch the thread is waste of time. Because the thread is not answered?

                   

                  Do the need full.

                   

                  thx,

                  csm_phil.