Photoshop Scripting - Update Progress Bar in a Window

丶灬走出姿态 提交于 2020-01-13 02:53:34

问题


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?


回答1:


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




回答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)
}



回答3:


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/



来源:https://stackoverflow.com/questions/11211323/photoshop-scripting-update-progress-bar-in-a-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!