Skip to main content
Les Harris
Inspiring
June 4, 2020
Answered

Saving generated book components with ExtendScript doesn't work

  • June 4, 2020
  • 2 replies
  • 1632 views

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. 

This topic has been closed for replies.
Correct answer frameexpert

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.

2 replies

frameexpert
Community Expert
Community Expert
June 4, 2020

Try using the SimpleSave method:

doc.SimpleSave (doc.Name, false);

www.frameexpert.com
Les Harris
Inspiring
June 4, 2020

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?

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
June 4, 2020

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.

www.frameexpert.com
Klaus Göbel
Legend
June 4, 2020

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=1
https://community.adobe.com/t5/framemaker/file-save-is-not-a-function/m-p/9082055?page=1