Tuesday, October 11, 2011

The Active Document

One way or another, nearly all FDK plug-ins and ESTK scripts, work with documents. (The most likely exception to this rule might be a script that worked strictly with book level information.)

Before a script can do anything with a document two things need to be true:
  • The document must be open. (Open and visible on screen are not the same thing.)
  • The script need to grab hold of the document's object or, in FDK parlance, identifier.

Once you have found the object that represents a document, you can access the objects that make up that document (the paragraphs, graphics, flows, frames and so forth).

It is possible to open documents using a script but for now, lets work with a document that is already open. In fact, lets work with not just any open document but with the document that has the user focus. This is the document where words typed at the keyboard would go and to which any other user action would apply. That document is known as the active document.

Use the following code to get the document object:

var doc = app.ActiveDoc; 

NOTE:  app is the application object. Its function is essentially the same as that of the FV_SessionId identifier in an FDK plug-in.

Use the following code to determine the document's file name and then display that name using an alert:

var name = doc.Name;
Alert(name, Constants.FF_ALERT_CONTINUE_NOTE);



 Remember, your active document must be saved to have a name!




 

No comments:

Post a Comment