2 Replies Latest reply on Jul 6, 2009 7:10 PM by John.Kordas

    CS3 JS progress bar function

    John.Kordas Level 1

      I'm trying to create a progress bar function but the code below creates 6 instances of the progress window rather than updating the info in the first window.  I've gone the for loop process to make progress bars work is this the only way it can be used or is there a way to tell if a window is open on if so update the bar and info of that window?

       

      to call the bar I use stagesLeft("Looking for duplicates",1)

       

      
      
      

      function stagesLeft(myText,stageVal){
         
          var myStop =6;
          var myPbValue = stageVal;
          var myWindow = new Window ( 'window',' Progress');
          var myProgressBar = myWindow.add ('progressbar', [12, 12, 350, 24], 0, myStop);
          var myStaticText = myWindow.add('statictext');
          myStaticText.bounds = [0, 0, 340, 20];
          myStaticText.alignment = "left";
         
              myWindow.show();
              myProgressBar.value = myPbValue;
              myStaticText.text = myText;
              myWindow.text = 'Stage '+ myPbValue + ' out of ' + myStop;

       

             
              if(myPbValue == 6){
              myWindow.close();
                  }
          }

        • 1. Re: CS3 JS progress bar function
          [Jongware] Most Valuable Participant

          ScriptUI needs some time to get used to :-) A 'simple' progress bar was also my very first try and I think I made similar mistakes. But nothing to worry about.

           

          The reason you get more than one window, of course, is this line in your function:

           

          myWindow = new Window ..

           

          (and subsequently myWindow.show();)

           

          You should create the window (and usually, immediately show it) somewhere at the beginning of your script in an initialization phase. That'll pop up the window in the state you created it. Make the variable holding the window a global one, so you can access it even when using functions to 'drive' it.

          In your update loop, you should only change the elements: myProgressBar.value, myStaticText.text, and myWindow.text. ScriptUI is smart enough to check if the elements are on screen, and changes them immediately.

          Only when you are done processing, you call myWindow.close().

          • 2. Re: CS3 JS progress bar function
            John.Kordas Level 1

            Thanks Jongware I knew it had to be something simple.

             

            Working version:

             

            
            

                var myStop =6;
                var myWindow = new Window ( 'window','Progress');
                var myProgressBar = myWindow.add ('progressbar', [12, 12, 350, 24], 0, myStop);
                var myStaticText = myWindow.add('statictext');
                myStaticText.bounds = [0, 0, 340, 20];
                myStaticText.alignment = "left";

             

             

            function stagesLeft(myText,stageVal){
                if(stageVal == 1){   
                    myWindow.show();
                    }
                    myProgressBar.value = stageVal;
                    myStaticText.text = myText;
                    myWindow.text = 'Stage '+ stageVal + ' out of ' + myStop;
                   
                    if(stageVal == 6){
                    myWindow.close();
                        }
                }

             

            To use the function:

             

             

            stagesLeft("This is the first stage",1)

             

            then further on in the script when another process is taking place

             

            stagesLeft("Here is stage 2 of this script",2)

             

            etc etc.

             

            Cheers, John.