12 Replies Latest reply on Nov 26, 2012 6:12 AM by Laubender

    How to add a Progress Bar

    designmon79 Level 1

      Hi All,

       

      How to add progress bar in script. I have gone through with forums but couldn't find any simple example.

       

      Could anybody please show me a simple js code with progress bar in indesing script.

       

      Thanks in advance for your support.

      Mon.

        • 1. Re: How to add a Progress Bar
          Peter Kahrel Adobe Community Professional & MVP

          It's described in this guide: http://www.kahrel.plus.com/indesign/scriptui.html

          But it may not be that easy.

           

          Peter

          • 3. Re: How to add a Progress Bar
            milligramme Level 3

            I have refered  these sample scripts

            http://www.adobe.com/products/indesign/scripting/

             

            choose

            > Scripting Resources > InDesign CS5 in-depth scripting guides

             

            and download

            Download the InDesign Scripting Guide scripts (ZIP, 832k )


            unzip it, if javascript, progressbar sample is here

             

            indesign_cs5_scripting_guide_scripts

            ├── javascript

            │   ├── userinterfaces
            │   │   └── progressbar
            │   │       ├── CallProgressBar.jsx
            │   │       └── ProgressBar.jsx

             

             

            you can also download other fuction scripts

             

            mg

            1 person found this helpful
            • 4. Re: How to add a Progress Bar
              designmon79 Level 1

              Thanks you all for your answer.

               

              I have gone through with your suggestion. But it seems not easy for me.

               

              Could you please help me to add the progress bar in below simple script.

               

              Thanks,

              Mon

               

               

              Here is my script code.

               

              var myFilePath = Folder.selectDialog("Please choose files:");

              myFilePath = new Folder (myFilePath);

              myFilePathContents = new Array();

              mySubFolders(myFilePath);

              var myDocument = app.documents[0];

              for (var j = 0; myFilePathContents.length > j; j++) {

              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

              var myDocument = app.open(myFilePathContents[j]);

              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

              //

              myDocument.viewPreferences.horizontalMeasurementUnits =MeasurementUnits.millimeters;

              myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;

              app.activeDocument.close(SaveOptions.yes);

              //

              }

              function mySubFolders(theFolder) {

              var myFileList = theFolder.getFiles();

              for (var i = 0; i < myFileList.length; i++) {

              var myFile = myFileList[i];

              if (myFile instanceof Folder){

              mySubFolders(myFile);

              }

              else if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {

              myFilePathContents.push(myFile);

              }

              }

              }

              alert("Done.")

              • 5. Re: How to add a Progress Bar
                designmon79 Level 1

                Please help me out to add the progress bar in this script.

                 

                Thanks in advance,

                Mon

                • 6. Re: How to add a Progress Bar
                  Cenchen Level 2

                  Here the sample coding.... and u have to change based on ur script.

                   

                   

                  var list = ["one", "two", "three", "four", "five", "six"];
                  var w = new Window ("palette","Progress Bar");
                  var progress = progress_bar (w, list.length);
                  for (var i = 0; i < list.length; i++)
                  {
                  progress.value = i+1;
                  // user functions
                  $.sleep (400);
                  }
                  progress.parent.close();
                  function progress_bar (w, stop)
                  {
                  var pbar = w.add ("progressbar", undefined, 1, stop);
                  pbar.preferredSize = [300,20];
                  w.show ();
                  return pbar;
                  }
                  • 7. Re: How to add a Progress Bar
                    Laubender Adobe Community Professional & MVP

                    @Cenchen – are you on Windows or on Mac? Frankly I had no luck with your code…

                     

                    I'm on Mac OSX 10.6.8 and just tested with InDesign CS5.5.

                     

                    Result:

                    The palette will show up, showing the first sixth of the progress bar, but will not change any further. After a while (I think after the $.sleep(400) is executed six times) it will close…

                     

                    A progress bar that unfortunately shows no progress (screen shot):

                    ProgressBarThatWillNotChange.png

                     

                    Of course I added a #targetengine  in the code…

                    The question is: how can we force the progress bar to be redrawn if it does not?

                     

                    One could add a new palette window every time the loop iterates, but that will become a flickering effect on the user side and adds up a lot of time in the overall speed of the script.

                     

                     

                    Uwe

                    • 8. Re: How to add a Progress Bar
                      Laubender Adobe Community Professional & MVP

                      Here I am adding a script snippet that will show a new progress bar every time the for loop iterates.
                      It's downside is that it would be very slow in a real world scenario:

                       

                      #targetengine "sessionProgressBar1"
                      
                      var list = ["one", "two", "three", "four", "five", "six"];
                      
                      var counter = 0;
                      
                      for (var i = 0; i < list.length; i++){
                      
                          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                          ++counter;
                      
                          var w = new Window ("palette","Progress Bar");
                          var pbar = w.add("progressbar", undefined, counter, list.length);
                          pbar.preferredSize = [300,20];
                          w.show();
                      
                          $.sleep (400);
                          if(counter === list.length){w.close();};
                      
                          };
                      
                      alert("Showing the window "+counter+" times.");
                      

                       

                      If you take that approach for a large quick iterating loop (without the $.sleep), you'll get a big performance problem and a flickering palette window …

                       

                      Uwe

                      • 9. Re: How to add a Progress Bar
                        Laubender Adobe Community Professional & MVP

                        In my first tests I also added the line with the:

                         

                        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                        

                         

                        But that makes no difference. On my OSX 10.6.8 the progress bar of the first version will not change.
                        Only building a new palette window every time the loop is iterating has worked (for me).

                         

                        Uwe

                        • 10. Re: How to add a Progress Bar
                          Marijan Tompa [tomaxxi] Level 4

                          Uwe,

                          if you set enableRedraw to false, progress bar will stop updating.

                           

                          --

                          Marijan (tomaxxi)

                          • 11. Re: How to add a Progress Bar
                            Laubender Adobe Community Professional & MVP

                            @Marijan – great! That was it.

                            Somehow, maybe some scripts executions ago, I must have set "enableRedraw" to false.

                             

                            Thanks a lot!

                             

                            Uwe

                            • 12. Re: How to add a Progress Bar
                              Laubender Adobe Community Professional & MVP

                              I should have read Peter Kahrel's "scriptui-2-0.pdf" more thoroughly.

                              On page 52 there is a sidenote saying:

                               

                              Note: in scripts that use progress bars, you cannot set

                              app.scriptPreferences.enableRedraw to false. If you do, the progress

                              bar doesn't display correctly. This is on Macs only.

                               

                              Of course that will also affect scripts that should run on both systems…

                               

                              Uwe