2009-10-22

Get Page of Window

What is the user looking at?

I've found this function very handy lately. If you are opening files without showing the window ( as strange as that might seem, it can be very useful ), you will need a reference to what the user is viewing. This function returns the page the the Adobe InDesign thinks the user is looking at.

From that page reference you can easily get the document reference (remember it might not be app.activeDocument or app.documents[0]. See some prior posts to know why, but opening documents without showing the window is a really good reason!

Now, for some ideas. If you know the page that the user is looking at, you have ways to control printing of just that page, exporting just that page, adding items to just that page, applying master pages to just that page, etc...

//
function pageOfWindow () {
//-------------------------------------------------------------------------
//-- P A G E O F W I N D O W
//-------------------------------------------------------------------------
//-- Generic: Yes for Adobe InDesign, but not InCopy
//-------------------------------------------------------------------------
//-- Purpose: To return a reference to a the page that Adobe InDesign
//-- considers the active page.
//-------------------------------------------------------------------------
//-- Arguments: None
//-------------------------------------------------------------------------
//-- Calls: Nothing.
//-------------------------------------------------------------------------
//-- Returns: A page reference to the page that Adobe InDesign considers
//-- the active page. If no pages can be found it returns null ;
//-------------------------------------------------------------------------
//-- Sample Use:
//~ var currentPage = pageOfWindow() ;
//-------------------------------------------------------------------------
//-- Notes: The page returned can be a Master Page
//-------------------------------------------------------------------------
//-- Written: 2009.09.22 by Jon S. Winters of electronic publishing support
//-- eps@electronicpublishingsupport.com
//-------------------------------------------------------------------------
//-- 2009.09.24 added error handling

try {
//-- close any StoryWindows
while ( new RegExp ('Story','i').test( app.activeWindow.reflect.name ) ) {
app.activeWindow.close() ;
}
} catch (err) {
var errorObject = err ;
return null ;
}
//-- Get the page reference for the window displayed in the
//-- active Layout Window
return app.activeWindow.activePage ;
}
//

No comments:

Post a Comment