2 Replies Latest reply on Feb 29, 2016 11:08 AM by K.Daube

    How to switch to the book window

    K.Daube Level 1

      Dear friends and experts,

      After performing a number of actions on the files of a book the last document is open and active.

      Now I should re-activate the book window to perform another set of actions (running through the book components).

      I have not found a method to switch/activate to the book window in a script.

      if (app.FirstOpenBook.ObjectValid()){
        alert ("We have a book") };
      else { alert ("There is no book in this session")};
      

      I can assure with this that there is a book, but how to make it active?

        • 1. Re: How to switch to the book window
          frameexpert Level 4

          Hi Klaus,

           

          You can store the book object in a variable so you can refer to it later. So you could do this:

           

          if (app.FirstOpenBook.ObjectValid ()) {
              var book = app.FirstOpenBook;
          }
          else {
              alert ("There is no open book in this session.");
          }
          

           

          or if the book is active when you start:

           

          if (app.ActiveBook.ObjectValid ()) {
              var book = app.ActiveBook;
          } 
          else {
              alert ("There is no active book.");
          }
          

           

          Now when you need to refer to the book in later code, just use the book variable from line 02.

           

          -Rick

          • 2. Re: How to switch to the book window
            K.Daube Level 1

            Rick, as often I was to fearful just to try something:

            As You point out it's that simple:

            if (app.FirstOpenBook.ObjectValid()){
              alert ("We have a book") 
              book = app.FirstOpenBook;
              bookComp = book.FirstComponentInBook
              while(bookComp.ObjectValid()) {                 // process only FM docs
                if (bookComp.BookComponentFileType === Constants.FV_BK_FM) {
                  docName = bookComp.Name;
                  alert ("docName= "+ docName);
                }
                bookComp = bookComp.NextBookComponentInDFSOrder;
              }
            };
            else { alert ("There is no book in this session")};