Skip to main content
K.Daube
Community Expert
Community Expert
February 29, 2016
Answered

How to switch to the book window

  • February 29, 2016
  • 1 reply
  • 622 views

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?

This topic has been closed for replies.
Correct answer frameexpert

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

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
February 29, 2016

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

www.frameexpert.com
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
February 29, 2016

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")};