Create a Book Packager using ExtendScript

You all must be familiar with the great power that lies in ExtendScript. With the scripting support in FrameMaker 10 you can easily automate time-consuming and repetitive tasks.

This Archive or Packager, which I am going to describe here, is one such utility developed using FrameMaker Scripting support.

Description

It copies a book to a target folder, given by the user, and gathers all the assets for that book and its chapters into this archive directory. All references in the documents are then made to point to these files. Once a book has been archived, you can zip the directory to create a compressed self-contained archive of your book. It handles all components of hierarchical books i.e. Folders, Groups, Folder Templates and nested books. Works on structured and unstructured documents as well.

Components that are archived:

Usage

Code Snippets

It essentially performs the following steps (script attached, original script can be found here):

  1. Create a menu “Archive” inside the File -> Utility menu:
var bookMenu = app.GetNamedMenu("BookUtilitiesMenu");
var newCmd=DefineCommand(1,"Archive" ,"Archive","");
var newCmd1=bookMenu.AddCommandToMenu(newCmd);
  1. It opens the Browse Folder dialog where the user can select the folder to be used to Archive his files. He can also create a new folder. In the directory you choose, the Archive plugin will create a subdirectory “Insets” to hold the referenced graphics and text insets
folderPath= ChooseFile("Select Archive Folder","","",Constants.FV_ChooseOpenDir,"");
insetPath = folderPath.concat("\\","Insets");
newFolder=new Folder (insetPath);
newFolder.create();
  1. It silently opens all the chapter files in the book, finds all the referenced files in those files, copies all referenced files to Insets folder, changes the document references, saves them, and silently closes all the files. The book, with the new component paths, is then saved at the Archive directory.
var inset=docId.FirstGraphicInDoc;
while(inset)
{
  if(inset.type==Constants.FO_Inset)
  {
    //copy inset to the new folder
    var oldPath=inset.InsetFile;
    var fullPath=getNewPathForInsets(oldPath); //user-defined function that creates new paths for the insets
    filecopy(oldPath,fullPath);
    inset.InsetFile=fullPath;
  }
  inset=inset.NextGraphicInDoc;
}
  1. At the end of operation it gives an Alert informing the user about the completion of the operation and the archived location.
Alert("Your achive is ready at \n" + folderPath ,Constants.FF_ALERT_CONTINUE_NOTE);

For further details see the attached script.

You can develop and use such similar utilities to eliminate manual effort and increase productivity. Do try the script and let us know your valuable feedback!

With best regards,
Anchal
Adobe FrameMaker Engineering Team