Copy link to clipboard
Copied
I have some scripts adapted from the FM_Outputs_CondText.jsx sample in FM10, but I just noticed today that the book is not getting updated. Seems like I need something in between these two commands:
FileSource = OpenBook(InputFile);
SavePdf(FileSource,InputFile.replace(/\.book$/i,"") + OutPutFiles[output_no]);
Copy link to clipboard
Copied
rlauriston,
You can use the following code snippet to update the book:
int status = Book.UpdateBook(updateParams:PropVals , updateReturnParams:PropVals)
Regards,
FrameGurus
Copy link to clipboard
Copied
That breaks the script, nothing happens at all.
UpdateBook(FileSource) or UpdateAll() cause script processing to halt.
Copy link to clipboard
Copied
Hm, maybe the following function snippet I've found elsewhere can close the gap.
function OpenBookFiles(bname)
var book = bname;
.
. existing code in that function
.
var props = GetUpdateBookDefaultParams();
var index = GetPropIndex(props, Constants.FS_ShowBookErrorLog);
props[index].propVal.ival = true; // is usually false for scripts, but I like to see if there are erors
var returnp = new PropVals();
book.UpdateBook(props, returnp);
}
Copy link to clipboard
Copied
Thanks franz josef gigler! I packaged this into a function:
function UpdateBook(book)
{
Console(" Updating book...");
var props = GetUpdateBookDefaultParams();
props[GetPropIndex(props, Constants.FS_ShowBookErrorLog)].propVal.ival = false;
var returnp = new PropVals();
book.UpdateBook(props, returnp);
Console(" Updated book...");
}
(I disabled errors for my purposes.)
Copy link to clipboard
Copied
I no longer have any conditions that are different between PDF and online help, so I no longer need such a complicated script. All I really need is:
open book
update book
save as pdf
close book
Copy link to clipboard
Copied
Have you tried it with all the chapter files in the book already open? If a file cannot be automatically opened because some error is blocking it, that might cause the UpdateBook to fail.
Copy link to clipboard
Copied
Yes, actually I left out the command that opens the .fm files:
FileSource = OpenBook(InputFile);
OpenBookFiles(FileSource)
UpdateBook(FileSource)
SavePdf(FileSource,InputFile.replace(/\.book$/i,"") + OutPutFiles[output_no]);
CloseAll()
Copy link to clipboard
Copied
Can you post the full text of the (relevant portion of) the script here ?
Copy link to clipboard
Copied
It's basically the FM_Outputs_CondText.jsx sample script. I noticed the other day that a new heading was missing from the TOC and realized the script was not updating the book.
/********************************************************************/
/* */
/* ADOBE SYSTEMS INCORPORATED */
/* Copyright 1986 - 2010 Adobe Systems Incorporated */
/* All Rights Reserved */
/* */
/* NOTICE: Adobe permits you to use, modify, and distribute this */
/* file in accordance with the terms of the Adobe license agreement */
/* accompanying it. If you have received this file from a source */
/* other than Adobe, then your use, modification, or distribution */
/* of it requires the prior written permission of Adobe. */
/* */
/********************************************************************/
/*
* Program Name:
* << FM_Outputs_Conditional_Text.jsx >>
*
* General Description:
* Book to Multiple PDF -> for generating Multiple PDF outputs on the basis of Conditional Text
*
*********************************************************************/
InputFile="C:\\Books\\Bk8.book" /* Edit the FULL path of the Book here - this book should have conditional text with the names - Comment / Red / Blue / Green */
var ShowList = new Array()
var HideList = new Array()
/* Output1: Show / Hide Conditions list here */
ShowList[0] = new Array("Comment", "Red");
HideList[0] = new Array("Blue", "Green");
/* Output2: Show / Hide Conditions list here */
ShowList[1] = new Array("Blue", "Green");
HideList[1] = new Array("Red", "Comment");
/* Define the list of Output file Names here. This would get appended to the original Book*/
var OutPutFiles = new Array("_Comment_Red.pdf", "_Blue_Green.pdf");
for (var output_no=0; output_no<OutPutFiles.length; output_no++) /* Optimize possible here - file needs to be opened once - the ShowHide needs to be shifted from OpenBookFiles */
{
/* The Book on which Conditional Text be applied before saving to PDF */
FileSource = OpenBook(InputFile);
/*Apply Conditions to each document in OpenBookFiles function */
OpenBookFiles(FileSource)
/* The Output Book PDF on which Conditional Text is applied before saving to PDF */
SavePdf(FileSource,InputFile + OutPutFiles[output_no]);
/* Close All Files */
CloseAll()
}
function ShowHide(FileId, CondName, showOrHide)
{
CondFmtId = FileId.GetNamedCondFmt (CondName)
if (showOrHide) /* If 1 then show else hide*/
CondFmtId.CondFmtIsShown = 1
else
CondFmtId.CondFmtIsShown = 0
FileId.ShowAll = 0 /* Setting it to ShowAll to apply the Condtional Text property*/
}
function OpenBook(filename)
{
openProp = GetOpenDefaultParams()
i=GetPropIndex(openProp,Constants.FS_FileIsOldVersion)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FontChangedMetric)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FontNotFoundInCatalog)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FontNotFoundInDoc)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_LanguageNotAvailable)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_LockCantBeReset)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_UpdateTextReferences)
openProp.propVal.ival=Constants.FV_DoNo
i=GetPropIndex(openProp,Constants.FS_UpdateXRefs)
openProp.propVal.ival=Constants.FV_DoNo
i=GetPropIndex(openProp,Constants.FS_UseAutoSaveFile)
openProp.propVal.ival=Constants.FV_DoNo
i=GetPropIndex(openProp,Constants.FS_UseRecoverFile)
openProp.propVal.ival=Constants.FV_DoNo
i=GetPropIndex(openProp,Constants.FS_AlertUserAboutFailure)
openProp.propVal.ival=false
i=GetPropIndex(openProp,Constants.FS_BeefyDoc)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FileIsInUse)
openProp.propVal.ival=Constants.FV_ResetLockAndContinue
i=GetPropIndex(openProp,Constants.FS_BookIsInUse)
openProp.propVal.ival=Constants.FV_ResetLockAndContinue
i=GetPropIndex(openProp,Constants.FS_MakeVisible)
openProp.propVal.ival=true
i=GetPropIndex(openProp,Constants.FS_RefFileNotFound)
openProp.propVal.ival=Constants.FV_AllowAllRefFilesUnFindable
i=GetPropIndex(openProp,Constants.FS_FileIsOldVersion)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FileIsStructured)
openProp.propVal.ival=Constants.FV_OpenViewOnly
i=GetPropIndex(openProp,Constants.FS_OpenFileNotWritable)
openProp.propVal.ival=Constants.FV_DoOK
retParm = new PropVals()
docOpen=Open(filename,openProp,retParm);
//alert(docOpen);
return docOpen;
}
function OpenBookFiles(bname)
{
//Initialising Current Component
var bookComp=bname.FirstComponentInBook;
var compId = bookComp.id;
//Loop for traversing hierarchy of book
while(compId)
{
var nextId = 0;
var parentId = 0;
var compType=bookComp.ComponentType;
//Assigning next component - If current component is Group or Folder(move downward in hierarchy)
if(Constants.FV_BK_FOLDER == compType || Constants.FV_BK_GROUP == compType)
{
var nextComp=bookComp.FirstComponentInBookComponent;
nextId = nextComp.id;
}
//Assigning next component - If current component is not a Group or Folder i.e. a file
if(nextId == 0)
{
var nextComp = bookComp.NextComponentInBook;
nextId = nextComp.id;
}
//Initialising parent component
var parentComp = bookComp;
parentId = parentComp.id;
//Moving upward in hierarchy if reached end of group or folder
while((nextId == 0) && (parentId != 0))
{
parentComp = parentComp.BookComponentParent;
nextComp = parentComp.NextComponentInBook;
parentId = parentComp.id;
nextId = nextComp.id;
}
//Opening the file
var fname = bookComp.Name;
fileId = openfile(fname) // Here openfile function is called
for (var i=0; i<ShowList[output_no].length; i++) /* Calling ShowHide function to Show */
ShowHide(fileId, ShowList[output_no], 1);
for (var i=0; i<HideList[output_no].length; i++) /* Calling ShowHide function to Hide */
ShowHide(fileId, HideList[output_no], 0);
//Iterating to next component
bookComp = nextComp ;
compId = bookComp.id;
}//end of loop
}
function openfile(filename)
{
openProp = GetOpenDefaultParams()
i=GetPropIndex(openProp,Constants.FS_FileIsOldVersion)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FontChangedMetric)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FontNotFoundInCatalog)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FontNotFoundInDoc)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_LanguageNotAvailable)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_LockCantBeReset)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_UpdateTextReferences)
openProp.propVal.ival=Constants.FV_DoNo
i=GetPropIndex(openProp,Constants.FS_UpdateXRefs)
openProp.propVal.ival=Constants.FV_DoNo
i=GetPropIndex(openProp,Constants.FS_UseAutoSaveFile)
openProp.propVal.ival=Constants.FV_DoNo
i=GetPropIndex(openProp,Constants.FS_UseRecoverFile)
openProp.propVal.ival=Constants.FV_DoNo
i=GetPropIndex(openProp,Constants.FS_AlertUserAboutFailure)
openProp.propVal.ival=false
i=GetPropIndex(openProp,Constants.FS_BeefyDoc)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FileIsInUse)
openProp.propVal.ival=Constants.FV_OpenViewOnly
i=GetPropIndex(openProp,Constants.FS_MakeVisible)
openProp.propVal.ival=true
i=GetPropIndex(openProp,Constants.FS_RefFileNotFound)
openProp.propVal.ival=Constants.FV_AllowAllRefFilesUnFindable
i=GetPropIndex(openProp,Constants.FS_FileIsOldVersion)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FileIsStructured)
openProp.propVal.ival=Constants.FV_OpenViewOnly
i=GetPropIndex(openProp,Constants.FS_OpenFileNotWritable)
openProp.propVal.ival=Constants.FV_DoOK
retParm = new PropVals()
fileOpen=Open(filename,openProp,retParm);
return fileOpen;
}
function openxml(filename,appname)
{
openProp = GetOpenDefaultParams()
i=GetPropIndex(openProp,Constants.FS_FileIsOldVersion)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_OpenAsType)
openProp.propVal.ival=Constants.FV_TYPE_XML
i=GetPropIndex(openProp,Constants.FS_StructuredOpenApplication)
openProp.propVal.sval=appname
i=GetPropIndex(openProp,Constants.FS_FontNotFoundInDoc)
openProp.propVal.ival=Constants.FV_DoOK
i=GetPropIndex(openProp,Constants.FS_FileIsInUse)
openProp.propVal.ival=Constants.FV_DoCancel
i=GetPropIndex(openProp,Constants.FS_AlertUserAboutFailure)
openProp.propVal.ival=Constants.FV_DoCancel
retParm = new PropVals()
fileOpen = Open(filename,openProp,retParm);
return fileOpen;
}
function SavePdf(file,pdfName)
{
var params = GetSaveDefaultParams()
var returnParamsp =new PropVals()
var i = GetPropIndex(params, Constants.FS_FileType)
params.propVal.ival =Constants.FV_SaveFmtPdf
file.Save(pdfName, params, returnParamsp)
return
}
function CloseAll()
{
doc=app.FirstOpenDoc
while(doc.id !=0)
{
doc2=doc.NextOpenDocInSession;
doc.Close(Constants.FF_CLOSE_MODIFIED);
doc = doc2;
}
book=app.FirstOpenBook
while(book.id !=0)
{
book2=book.NextOpenBookInSession;
book.Close(Constants.FF_CLOSE_MODIFIED);
book=book2
}
}
Copy link to clipboard
Copied
I have a sample project if anyone wants to look at it.
Copy link to clipboard
Copied
Hi,
If you can zip the sample project and script(s) and send them to jang at jang dot nl I can certainly have a look. It might not be immediately due to lots of paid work on my desk right now, but then it might turn out to be simpler than expected.
Ciao
Jang
Copy link to clipboard
Copied
Robert,
What's happening? Did you solve the problem yet? If so, let us know what the solution was. If not, send me the files and I will take a look.
Ciao
Jang