Skip to main content
Inspiring
February 9, 2013
Answered

Progressbar in script UI problem

  • February 9, 2013
  • 1 reply
  • 6287 views

Hi friends

I´m trying to add a window with a simple progress bar. But I´m having 2 problems. To better explain I made a simple example that reproduces the intent:

#target Bridge

var d1 = new Window ("dialog", "Show images", [0,0,0,0])

d1.size = [600,290]

d1.center()

var exec = d1.add ("button", [0,0,0,0], "Run", {name:"ok"})

exec.size = [80,30]

exec.location = [410,240]

exec.onClick = function (){

   

    d1.close() //first problem is here

   

    var d2 = new Window ("dialog", "Progress", [0,0,0,0])

    d2.size = [230,80]

    d2.center()

   

    var bProgress = d2.add ("progressbar", [0,0,0,0], 0)

    bProgress.size = [200,20]

    bProgress.location = [15,20]

   

    var comment = d2.add ("statictext", [0,0,0,0], "Running numbers")

    comment.size = [200,20]

    comment.location = [15,45]

   

    d2.show()

   

    for (var g=0; g<10; g++){

        bProgress.value = bProgress.value + 10

        alert(g)

        }

   

    }

d1.show()

The 2 problems I´m having are:

1: When pressing the OK in the first dialog..to run the action...I passed a command to close the dlg1. And it does not close (you will se the 2 dialogs keep opened at the same time)

2: Progress bar does not work. It´s expecting myself to close the dlg2 in order to start running the "for" cycle.

--

What Am I missing??

Thank you a lot for the help

Best Regards

Gustavo

Message was edited by: Gustavo Del Vechio

This topic has been closed for replies.
Correct answer Paul Riggott

There are some examples here...

http://www.ps-scripts.com/bb/viewtopic.php?f=13&t=786&sid=7222ff525179a4b47ee49b70d787342e

A progress bar is normally run as a a palette not a dialog...

#target bridge
app.bringToFront();
var d1 = new Window ("dialog", "Show images", [0,0,0,0]);
d1.size = [600,290];
var exec = d1.add ("button", [0,0,0,0], "Run", {name:"ok"});
exec.size = [80,30];
exec.location = [410,240];
exec.onClick = function (){
d1.visible=false;
d1.close();
var value = 0;
var win = new Window("palette{text:'Please be patient...',bounds:[100,100,580,140]," +
               "progress:Progressbar{bounds:[20,10,460,30] , minvalue:0,value:" + value + "}};" );
var d = win.graphics;
d.backgroundColor = d.newBrush(d.BrushType.SOLID_COLOR, [0.00, 0.00, 0.00, 1]);
win.progress.maxvalue = 10;
Count =10;
while(Count > 0){
   win.center();
   win.show();
   Count--;
   win.progress.value++;
   win.layout.layout(true);
   alert(Count);
}
}
d1.center();
d1.show();

1 reply

Paul Riggott
Paul RiggottCorrect answer
Inspiring
February 9, 2013

There are some examples here...

http://www.ps-scripts.com/bb/viewtopic.php?f=13&t=786&sid=7222ff525179a4b47ee49b70d787342e

A progress bar is normally run as a a palette not a dialog...

#target bridge
app.bringToFront();
var d1 = new Window ("dialog", "Show images", [0,0,0,0]);
d1.size = [600,290];
var exec = d1.add ("button", [0,0,0,0], "Run", {name:"ok"});
exec.size = [80,30];
exec.location = [410,240];
exec.onClick = function (){
d1.visible=false;
d1.close();
var value = 0;
var win = new Window("palette{text:'Please be patient...',bounds:[100,100,580,140]," +
               "progress:Progressbar{bounds:[20,10,460,30] , minvalue:0,value:" + value + "}};" );
var d = win.graphics;
d.backgroundColor = d.newBrush(d.BrushType.SOLID_COLOR, [0.00, 0.00, 0.00, 1]);
win.progress.maxvalue = 10;
Count =10;
while(Count > 0){
   win.center();
   win.show();
   Count--;
   win.progress.value++;
   win.layout.layout(true);
   alert(Count);
}
}
d1.center();
d1.show();

Inspiring
February 9, 2013

Hi Paul

Thank you a lot as ever. As a palette instead of dialog it worked. How about a script for Photoshop? Since Photoshop does not accept dialogs of "palettes", how could I set a progress bar working when targetting Photoshop???

And..I´m curious. Why it did not respect the call d1.close()?? (You need to pass "false" to a "d1.visible" property in order to hide that dialog).

Best Regards

Gustavo.

Paul Riggott
Inspiring
February 9, 2013

I was just trying to see if I could close the dialog window, when it wouldn't I tried to hide it, neither works. This is because of the Bridge scripting engine. It's yet another bug!

If You change the target to photoshop the same code will be run correctly in Photoshop and the main window will close.