Question

I want to show a progress bar for one of my Photoshop scripts. If I do work inside a button click event then I'm able to update the progress bar without any problems.

For this script, no user interaction is required. I want to: - Show the Window - Update the progress bar as work is done - Close the Window

var win = new Window("dialog{text:'Progress',bounds:[100,100,400,150],\ bar:Progressbar{bounds:[20,20,280,31] , value:0,maxvalue:100}};");
win.show();

for(...){
    //do work here

    //update progress
    win.bar.value = ...;
}

win.close();

The problem is, win.show(); blocks until the user closes the window. I've also tried to add an onClose handler then close the window immediately, but the window does not ever show.

Any ideas on how I could get a progress bar to work?

Was it helpful?

Solution

The window class dialog is a MODAL dialog and requires you to close it before the execution continues.

Use the class window to create a non-blocking window:

var win = new Window("window{text:'Progress',bounds:[100,100,400,150],bar:Progressbar{bounds:[20,20,280,31] , value:0,maxvalue:100}};");
win.show();

for(...){
    //do work here

    //update progress
    win.bar.value = ...;
}

win.close();

However, you will run into the next problem here. Depending on what you are doing in the loop, photoshop will not update the UI fast enough to see the progress bar moving. This is where I got stuck :/

OTHER TIPS

Ive run onto WaitForRedraw snippet one time, and maybe it will make ps redraw UI? Dont have time to check it, just an idea.

function WaitForRedraw(){
var eventWait = charIDToTypeID("Wait")
var enumRedrawComplete = charIDToTypeID("RdCm")
var typeState = charIDToTypeID("Stte")
var keyState = charIDToTypeID("Stte")
var desc = new ActionDescriptor()

desc.putEnumerated(keyState, typeState, enumRedrawComplete)
executeAction(eventWait, desc, DialogModes.NO)
}

You may want to consider using app.refresh() or waitForRedraw(). There is a window.update(), but it didnt seem to solve this problem for me.

Here is the source: http://www.davidebarranca.com/2012/10/scriptui-window-in-photoshop-palette-vs-dialog/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top