Copy link to clipboard
Copied
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.
I am sorry for not looking more closely at your code. bookToc is a BookComponent object, but you can't save a BookComponent directly; you need to save its Doc object. So, if the bookToc is open, you will have to loop through the currently open documents so you can grab its Doc object and save it.
Copy link to clipboard
Copied
Hi Les,
saving the book can't work, because you do not set the appropriate parameters.
Here are 2 links to discussion about saving a book or doc that could make things clearer.
https://community.adobe.com/t5/framemaker/latest-fm-scripting-guide-not-up-to-date/m-p/10728190?page...
https://community.adobe.com/t5/framemaker/file-save-is-not-a-function/m-p/9082055?page=1
Copy link to clipboard
Copied
Try using the SimpleSave method:
doc.SimpleSave (doc.Name, false);
Copy link to clipboard
Copied
Thank you, Rick.
bookToc.SimpleSave (bookToc.Name, false) gives the same result: "bookToc.SimpleSave is not a function". Can you suggest anything else to look at?
Copy link to clipboard
Copied
I am sorry for not looking more closely at your code. bookToc is a BookComponent object, but you can't save a BookComponent directly; you need to save its Doc object. So, if the bookToc is open, you will have to loop through the currently open documents so you can grab its Doc object and save it.
Copy link to clipboard
Copied
Thanks again, Rick. I wasn't sure exactly how to go about that, but I searched and found this:
I added something similar to the very end of the script and now it's working perfectly.
var openDoc;
openDoc = app.FirstOpenDoc;
while (openDoc.ObjectValid () === 1) {
saveObject(openDoc,openDoc.Name);
docToClose = openDoc;
openDoc = openDoc.NextOpenDocInSession;
docToClose.Close(1);
}
I appreciate your help very much!