I'm trying to create a progress bar to display how much of a script has run. Problem is, I can't get the progress bar to reliably update without using an app.refresh() call. Ideally I don't want to do that as it causes a redraw of the open documents which will potentially be very large and will slow everything down significantly. I've stripped the code down to this which, when I run in CS5 (on Windows 7), I get very intermittent results:
Code: Select allvar progressWindow = new Window ("palette", "Please wait...");
progressBar = progressWindow.add("progressbar", undefined, 0, 100);
progressBar.preferredSize = [300,20];
progressWindow.enabled = true;
progressWindow.show();
for(i=0; i<11; i++)
{
progressBar.value = i * 10;
progressWindow.update();
$.sleep(200);
}
1 time out of 10 the progress bar will update correctly. Other times it will refresh up to around half way, sometimes a tenth of the way, sometimes not at all.
Any ideas what may be going on?
Thanks
Another progress bar problem
-
PhotoSpot_scripter
Another progress bar problem
I tried your code on my PC (win7 64bit) with CC, CS6 and CS5 versions, and it all worked perfectly.
I know this isn't much help, but at least you know on other systems your logic seems to be just fine...
I know this isn't much help, but at least you know on other systems your logic seems to be just fine...
-
lambo75
Another progress bar problem
Thanks for trying that. At least I know that the code's good. I've tried it on another machine and I'm having the same issue. Maybe a Windows or Photoshop setting is causing the problem
-
Mike Hale
Another progress bar problem
I would say use redraw(). Unlike app.refresh(), which can slow down a script, window.redraw() is every fast as it only has to change a small part of the screen.
Code: Select all var progressWindow = new Window ("palette", "Please wait...");
progressBar = progressWindow.add("progressbar", undefined, 0, 1000);
progressBar.preferredSize = [300,20];
progressWindow.enabled = true;
progressWindow.show();
var time = new Timer();
time.start();
for(i=0; i<1000; i++)
{
progressBar.value = i;
// run once and jot down the time then comment out the line below and rerun.
// on my system tthe difference is the same as the normal variation between runs. ( the same code will vary a flittle in the tenth of a second range )
progressWindow.update();
$.sleep(20);
}
time.stop();
alert('Time: '+ time.getTime() );
function Timer() {
// member properties
this.startTime = new Date();
this.endTime = new Date();
// member methods
// reset the start time to now
this.start = function () { this.startTime = new Date(); }
// reset the end time to now
this.stop = function () { this.endTime = new Date(); }
// get the difference in milliseconds between start and stop
this.getTime = function () { return (this.endTime.getTime() - this.startTime.getTime()) / 1000; }
// get the current elapsed time from start to now, this sets the endTime
this.getElapsed = function () { this.endTime = new Date(); return this.getTime(); }
// pause for this many seconds
this.pause = function ( inSeconds ) {
var t = 0;
var s = new Date();
while( t < inSeconds ) {
t = (new Date().getTime() - s.getTime()) / 1000;
}
}
}
Code: Select all var progressWindow = new Window ("palette", "Please wait...");
progressBar = progressWindow.add("progressbar", undefined, 0, 1000);
progressBar.preferredSize = [300,20];
progressWindow.enabled = true;
progressWindow.show();
var time = new Timer();
time.start();
for(i=0; i<1000; i++)
{
progressBar.value = i;
// run once and jot down the time then comment out the line below and rerun.
// on my system tthe difference is the same as the normal variation between runs. ( the same code will vary a flittle in the tenth of a second range )
progressWindow.update();
$.sleep(20);
}
time.stop();
alert('Time: '+ time.getTime() );
function Timer() {
// member properties
this.startTime = new Date();
this.endTime = new Date();
// member methods
// reset the start time to now
this.start = function () { this.startTime = new Date(); }
// reset the end time to now
this.stop = function () { this.endTime = new Date(); }
// get the difference in milliseconds between start and stop
this.getTime = function () { return (this.endTime.getTime() - this.startTime.getTime()) / 1000; }
// get the current elapsed time from start to now, this sets the endTime
this.getElapsed = function () { this.endTime = new Date(); return this.getTime(); }
// pause for this many seconds
this.pause = function ( inSeconds ) {
var t = 0;
var s = new Date();
while( t < inSeconds ) {
t = (new Date().getTime() - s.getTime()) / 1000;
}
}
}
-
lambo75
Another progress bar problem
Thanks for your reply Mike. Got dragged off to do other stuff and completely forgot about this
I can't get the redraw() to work. I've hunted the object model library but can't find any reference to it. Am I missing something? I'm running PS CS5.
Thanks.
I can't get the redraw() to work. I've hunted the object model library but can't find any reference to it. Am I missing something? I'm running PS CS5.
Thanks.