I have a script that is working fine but can take a lot of time to complete. This is a javascript document and runs several functions.
This script runs within InDesign and is javascript based. The ExtendScript Toolkit provides several demoscripts and one of them is SnpCreateProgressBar.jsx
.
Now I want to add the progressbar to my current script but I'm not entirely sure how to do this.
Without posting the entire code here I'll do a function. This is repeated throughout the script.
var myDoc = app.activeDocument;
var myTables = myDoc.stories.everyItem().tables.everyItem();
var myTableElements = myTables.getElements();
function basicSearchReplace(findWhat, changeTo){
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findChangeGrepOptions = NothingEnum.nothing;
app.findGrepPreferences.findWhat = findWhat;
app.changeGrepPreferences.changeTo = changeTo;
myDoc.changeGrep();
}
basicSearchReplace ('^~8 ', '~8\\t');
basicSearchReplace ('^·( |\\t)', '~8\\t');
The SnpCreateProgressBar.jsx
can be found here
Maybe there is another extendscript way to create a progress bar?
--- Small Update ---
So after some Googeling and testing I came up with :
function SnpCreateProgressBar ()
{
this.windowRef = null;
}
SnpCreateProgressBar.prototype.run = function() {
var win = new Window("palette", "SnpCreateProgressBar", [150, 150, 600, 260]);
win.pnl = win.add("panel", [10, 10, 440, 100], "Script Progress");
win.pnl.progBar = win.pnl.add("progressbar", [20, 35, 410, 60], 0, 100);
win.pnl.progBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], "0%");
win.show();
while(win.pnl.progBar.value < win.pnl.progBar.maxvalue)
{
// this is what causes the progress bar increase its progress
win.pnl.progBar.value++;
win.pnl.progBarLabel.text = win.pnl.progBar.value+"%";
$.sleep(10);
}
alert('Done!');
win.close();
};
if(typeof(SnpCreateProgressBar_unitTest) == "undefined") {
new SnpCreateProgressBar().run();
}
Now I don't think I fully understand. If I place my "to-run" code in the while loop it just executes that and runs the process bar at the end... Same goes for the if-loop at the bottom
What am I not understanding?