Why does my script never complete?
Hi all
I'm fairly new to scripting, but not InDesign.
I've adapted a script I found online to help me with a document created via Data Merge. The merged document has about 1900 pages, half of which have a 26 row / 3 column table on them.
The script is small, and is designed to remove any blank rows from those tables.
Testing on one page was fine - it took a second or so to run. But when I run it on the full, 1900 page document it never seems to end. It's been running about 5 hours now on my Win10, 64-bit, i7-6400U / 8gb laptop, and is still on the hourglass. Is it that my RAM is just insufficient?
I can leave it all night but have more documents to run, and would like to understand scripting performance better. So can anyone comment on why it may be taking so long?
var myDocument = app.activeDocument;
myDocument.preflightOptions.preflightOff = true; // for performance
var c = "";
for(var i=myDocument.textFrames.length-1; i>=0; i--){
for(var j=myDocument.textFrames[i].tables.length-1; j>=0; j--){
for(var k=myDocument.textFrames[i].tables[j].rows.length-1; k>=0; k--){
c = myDocument.textFrames[i].tables[j].rows[k].cells.everyItem().contents.join("");
c = trim(c);
if (c.charCodeAt(0) == 65279 && c.length <= 12){ // Empty row conditions
myDocument.textFrames[i].tables[j].rows[k].remove();
}
}
}
}
function trim (str) {
return str.replace(/^\s+/,'').replace(/\s+$/,'');
}
myDocument.preflightOptions.preflightOff = false;
What I especially don't understand is why processing a 1900 page document takes so much longer than 1900 x the time to process 2 pages.
I've closed all other programs and documents, turned preflight off, set display performance to fast...
Task Managr reports the CPU around 40% and memory does now seem to be all in use.
Is my only solution to quit the current process, split this into smaller runs and then combine after converting to PDF?
Thank you for any help
