Photoshop ScriptUI: Show a dialog window, close it, show it again gives an empty full size window

人走茶凉 提交于 2020-06-29 12:27:33

问题


In my script for Photoshop CC 2015 (Windows 10), written in JavaScript, I am processing all layers of the active document in a loop and want to show a setup dialog in each step.

For simplification, take the following working example. The window is defined outside the loop, and among other steps which are stripped here, the window is shown once every step in the loop:

#target photoshop

var w = new Window('dialog', 'Title');
var b = w.add('button', undefined, 'OK');

for (var i = 0; i < 3; i++) {
    // other code
    w.show();
    // other code
}

When you execute it, a small dialog window with just one "OK" button appears, as expected. You can close it using the "OK" button. But every consecutive w.show() produces a blank window that almost fills the entire screen, with no controls whatsoever. It can only be closed using the ESC key.

I tried overriding the b.onClick event and manually call close(), but that did not change anything.

Upon inspection of the w variable, it is obvious that the bounds, respectively location and size somehow got changed. I tried resetting these values to their previous state, and the window size is restored. However, the button is still not visible.

Am I missing something? How can I get the dialog window to show up correctly more than once?


回答1:


try this code, it works for me with Photoshop CC + OSX.

w.close() destroy dialog window, so you should create again.

press a button named 'ok', press return key are same as w.close().

#target 'photoshop'

for (var i = 0; i < 3; i++) {
  var w = W();
  $.writeln(w.show());
}

function W () {
  var w = new Window('dialog', 'Title');
  var b = w.add('button', undefined, 'OK', {name:'ok'});
  return w
}


来源:https://stackoverflow.com/questions/38701446/photoshop-scriptui-show-a-dialog-window-close-it-show-it-again-gives-an-empty

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