Photoshop Scripting - Update Progress Bar in a Window
Asked Answered
D

3

7

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?

Dynamite answered 26/6, 2012 at 15:58 Comment(0)
C
8

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 :/

Cratch answered 22/8, 2012 at 12:25 Comment(2)
Use win.update() each time you increment the bar to force a UI update.Megalocardia
Are you sure this works on slower systems as well. I think it technically doesn't force windows to update, it just invalidates the window and then Windows OS will redraw when it have the time to do so (low priority). On a slow system this will be done after the loop has finished...Cratch
D
2

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)
}
Donaldson answered 11/1, 2013 at 2:1 Comment(0)
D
1

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/

Divergence answered 31/7, 2015 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.