Another progress bar problem

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

lambo75

Another progress bar problem

Post by lambo75 »

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

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

PhotoSpot_scripter

Another progress bar problem

Post by PhotoSpot_scripter »

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...
lambo75

Another progress bar problem

Post by lambo75 »

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

Post by Mike Hale »

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;
      }
   }
}
lambo75

Another progress bar problem

Post by lambo75 »

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.