Copy link to clipboard
Copied
Using FM 11
ExtendScript
Windows 7
I'm running an ExtendScript from the FM Startup directory, by starting FM from a batch file. The Extendscript opens multiple book files (one at a time) and does a save as pdf for each one. FrameMaker terminates the script with a timeout error at random points in the script after only one or two saves. The Extendscript runs fine when I run it from the FM Scripting window. It only times out when I run it as a startup script. Is there some workaround for this? Sadly, I find no documentation about this.
Copy link to clipboard
Copied
Hi Diana, Does the batch file do anything else besides start up FrameMaker? Can you take a screenshot of the error message and post it? Thanks. -Rick
Copy link to clipboard
Copied
Hi Rick,
Yes, the batch file does a little basic dos-mode logging but that is the only other thing it does besides start FrameMaker. I'll attach two screen shots. The message tends to vary slightly, pointing to different lines of the ExtendScript, but basically saying it timed out, each time.
Thanks,
Diana
Copy link to clipboard
Copied
Thanks for the screenshots. I am unfamiliar with these errors, so I may need to see your code. Let me know if you want to meet. Thanks. -Rick
Copy link to clipboard
Copied
Hi Diana,
I too have never seen an ES timeout error, but I have never tried to run an ES script the way you are. It is an interesting methodology and it seems like it should work. My initial suspicion is that there is some kind of bug in FM, not in your code. I don't see how a simple Date constructor should cause such a big problem.
If the script reliably saves at least one book, consider this possible workaround... change your script to process a single book only and restart FM for each book. Your DOS script could write a small text file somewhere that contains a book path, then your ExtendScript could read that file to determine which book to process. A bit more overhead, but I would try it if you can't find a way to fix the original problem.
Russ
Copy link to clipboard
Copied
Thanks, Rick. Here is the body of the Extendscript that is in the FM Startup directory. The batch file starts FM and then this script gets kicked off.
main();
function main() {
log("Starting the script.");
var controlFile = File("G:\\fmToPdf\\fmToPdf.control");
var controlContent = null;
if(controlFile.exists === true) {
// Open the file.
controlFile.open("r"); // r means read only.
// Read the file contents into a variable.
controlContent = controlFile.read();
// Close the file.
controlFile.close();
}
var bookRegEx = /^book="(.*)"/;
var targetRegEx = /^target="(.*)"/;
var pathRegEx = /([^\\]+)$/;
var lines = controlContent.split("\n");
for (i = 0; i < lines.length; i++) {
var line = lines;
if (bookRegEx.test(line) === true) {
var result = line.match(bookRegEx);
var inBook = result[1];
var pathComponents = pathRegEx.exec(inBook);
var fileName = pathComponents[1].replace("book", "pdf");
for (i = i + 1; i < lines.length; i++) {
line = lines;
if (targetRegEx.test(line)===true) {
result = line.match(targetRegEx);
var outBook = result[1] + fileName;
log("Starting to generate: " + outBook);
fileId = openBook(inBook);
saveBook(fileId,outBook);
closeBook(fileId);
log("Finished with: " + outBook);
} else {
break;
}
}
}
}
// close FrameMaker
Constants.FF_CLOSE_MODIFIED = 1;
app.Close (Constants.FF_CLOSE_MODIFIED);
log("We're done.");
return;
}
function openBook(filename)
{
var openProp = GetOpenDefaultParams();
var retParm = new PropVals();
var BookOpen=Open(filename,openProp,retParm);
return BookOpen
}
// save as pdf
function saveBook(file, pdfName)
{
var saveProp = GetSaveDefaultParams();
var i = GetPropIndex(saveProp, Constants.FS_FileType);
saveProp.propVal.ival = Constants.FV_SaveFmtPdf;
//i = GetPropIndex (saveProp, Constants.FS_DontNotifyAPIClients)
//saveProp.propVal.ival = true;
var retParmspdf = new PropVals();
// pdf settings
file.PDFBookmark = true;
file.PDFBookmarksOpenLevel = Constants.FV_PDFBookmarksOpenDefaultLevel;
file.PDFConvertCMYKtoRGB = true;
file.PDFDistillerAbsent = 0;
file.PDFJobOption = "High Quality Print";
file.PDFSeparateFiles = false;
file.DocIsViewOnly = 1;
file.Save(pdfName, saveProp, retParmspdf);
return
}
// close file
function closeBook(filename)
{
filename.Close (Constants.FF_CLOSE_MODIFIED);
}
function log(message, reset)
{
var logfile = File("G:\\fmToPdf\\fmToPdf.log");
var openMode = (reset === undefined) ? "a" : "w";
logfile.open(openMode);
logfile.writeln(getTimeStamp() + " " + message);
logfile.close();
}
function getTimeStamp(){
var d = new Date();
var timestamp = d.getFullYear() + "." +
zeroFill ((d.getMonth() + 1), 2) + "." +
zeroFill (d.getDate(), 2) + " " +
zeroFill (d.getHours(), 2) + ":" +
zeroFill (d.getMinutes(), 2) + ":" +
zeroFill (d.getSeconds(), 2);
return timestamp;
}
function zeroFill( number, width )
{
width -= number.toString().length;
if ( width > 0 )
{
return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
}
return number + ""; // always return a string
}