Skip to main content
September 21, 2010
Question

Type of window for progress bars?

  • September 21, 2010
  • 2 replies
  • 7823 views

What type of window (window/palette/dialog etc) is best for progress bars?

I´m using window now, but they can sometimes by accident get hidden behind the document.

I dont think dialog works, since i do things to the document, but it would be nice since they allways stay on top.

/Pontus

This topic has been closed for replies.

2 replies

Marc Autret
Legend
September 21, 2010

The palette container seems to work fine.

Here is the ProgressBar object that I use in most of my scripts:

var ProgressBar = function(/*str*/title)
{
     var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),
          pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),
          st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');
     st.justify = 'center';
     w.center();
     this.reset = function(msg,maxValue)
          {
          st.text = msg;
          pb.value = 0;
          pb.maxvalue = maxValue||0;
          pb.visible = !!maxValue;
          w.show();
          };
     this.hit = function() {++pb.value;};
     this.hide = function() {w.hide();};
     this.close = function() {w.close();};
};


//------------------------------------------------
//      SAMPLE CODE
//------------------------------------------------

function main()
{
     var pBar = new ProgressBar("Script Title");
     var i;
     
     // Routine #1
     pBar.reset("Processing Routine #1...", 100);
     for( i=0 ; i < 100; ++i, pBar.hit() )
          {
          $.sleep(10);
          }
     
     // Routine #2
     var i;
     pBar.reset("Processing Routine #2...", 10);
     for( i=0 ; i < 10; ++i, pBar.hit() )
          {
          $.sleep(300);
          }
     
     pBar.close();
}
main();

@+

Marc

October 13, 2010

I put Marc Autrets progress bar function in my script, triggering it from a menu item, same result, its not updating until its finished or i give an alert.

#targetengine "session" var ProgressBar = function(/*str*/title) {      var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),           pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),           st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');      st.justify = 'center';      w.center();      this.reset = function(msg,maxValue)           {           st.text = msg;           pb.value = 0;           pb.maxvalue = maxValue||0;           pb.visible = !!maxValue;           w.show();           };      this.hit = function() {++pb.value;};      this.hide = function() {w.hide();};      this.close = function() {w.close();}; }; //------------------------------------------------ //      SAMPLE CODE //------------------------------------------------           test_menu = app.menus.item('$ID/Main').submenus.add('Test'); app.scriptMenuActions.everyItem().remove(); app.menus.item('$ID/Main').submenus.item('Test').submenus.everyItem().remove(); var test_sub_menu = app.scriptMenuActions.add('Test'); test_sub_menu.eventListeners.add('onInvoke', function() {      var pBar = new ProgressBar("Script Title");      var i;      // Routine #1      pBar.reset("Processing Routine #1...", 100);      for( i=0 ; i < 100; ++i, pBar.hit() )      {           $.sleep(10);      }      // Routine #2      var i;      pBar.reset("Processing Routine #2...", 10);      for( i=0 ; i < 10; ++i, pBar.hit() )      {           $.sleep(300);      }      pBar.close(); }); test_menu.menuItems.add(test_sub_menu);

Participating Frequently
January 21, 2011

The progressbar which is not updating untill finishing the whole task may possibly be an issue of InDesign CS4.

I had the same problem when trying to run the script in InDesign CS4 (Mac). Just try the same thing in CS5, for me it worked...

Peter Kahrel
Community Expert
Community Expert
September 21, 2010

You can use palette and window, but not dialog. Dialogs grab all attention: so long as one is displayed you can't do anything else.

Peter