Saving generated book components with ExtendScript doesn't work
I am working on a script to use existing non-generated book files to create a new FrameMaker book. I have the following code to create a TOC and list of figures:
var loc = newPath.substring(0, newPath.lastIndexOf("\\"));
bookToc = oBk.NewSeriesBookComponent (oBk.FirstComponentInBook);
bookToc.BookComponentType = Constants.FV_BK_TOC;
bookToc.Name = loc + "\\TOC.fm";
bookToc.ExtractTags = vExtractList;
bookToc.GenerateInclude = 1;
// add LOF to oBk and set it up (type = Constants.FV_BK_LIST_FIGURE)
bookLof = oBk.NewSeriesBookComponent (bookToc);
bookLof.BookComponentType = Constants.FV_BK_LIST_FIGURE;
bookLof.Name = loc + "\\LOF.fm";
bookLof.ExtractTags = new Strings ("Figure1", "Figure");
bookLof.GenerateInclude = 1;
$.writeln("bookLof.ObjectValid() = ", bookLof.ObjectValid());
// generate TOC and LOF
oBk.SimpleGenerate(0,1);
// save and close TOC and LOF - THIS ALWAYS FAILS
// but if I comment out the next four lines the script runs to completion
saveObject(bookToc,bookToc.Name);
bookToc.Close(1);
saveObject(bookLof,bookLof.Name);
bookLof.Close(1);
// update oBk
$.writeln(bookToc.ObjectValid());
bkUpdate(oBk);
// save and close new book..."saveObject" works fine for books and non-generated files
saveObject(oBk,oBk.Name);
oBk.Close(1);
I cannot save and close the TOC and LOF files. If I comment out those lines the script runs to completion. The generated files are added to the book and appear in separate windows. At this point I can manually save and close the generated files, but I'd like the script to handle that.
Here's the "saveObject" and "bkUpdate" code...the ESTK is telling me that "obj.Save is not a function":
function saveObject(obj,saveAsName)
{
saveParams = GetSaveDefaultParams();
returnParams = new PropVals();
obj.Save(saveAsName, saveParams, returnParams);
return 0;
}
function bkUpdate(obj)
{
var updateParams = GetUpdateBookDefaultParams();
var updateReturnParams = new PropVals();
var index = GetPropIndex(updateParams, Constants.FS_UpdateBookGeneratedFiles);
updateParams[index].propVal.ival = true;
var index = GetPropIndex(updateParams, Constants.FS_MakeVisible);
updateParams[index].propVal.ival = true;
obj.UpdateBook(updateParams, updateReturnParams);
return 0;
}
As always, any advice is most appreciated.
