4 Replies Latest reply on Jul 31, 2014 1:42 PM by HarveyLiu

    How can add a progress bar into script?

    HarveyLiu

      Hi,

       

      I got a script for gen pdf

      I want put a progress bar, and make it working

      but I don't know where I can put the progress bar

      and how

       

      //=====================================================================

       

      var doc = app.documents; 

      app.findTextPreferences = null; 

      app.findTextPreferences.underline = true; 

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

              var found = doc[i].findText(); 

              var _pages = []; 

              for(var j=0;j<found.length;j++) 

              { 

                      var txfms = found[j].texts[0].parentTextFrames; 

                      for(var k=0;k<txfms.length;k++) 

                      { 

                              _pages.push(txfms[k].parentPage.name); 

                          } 

                  } 

              for(var j=0;j<_pages.length;j++) 

              { 

                      if(_pages[j] === _pages[j-1]) 

                      { 

                              _pages.splice(j,1); 

                          } 

                  } 

              if(_pages.length != 0) 

              { 

                      app.pdfExportPreferences.pageRange = _pages.toString(); 

                      doc[i].exportFile(ExportFormat.PDF_TYPE, new File(doc[i].fullName.toString().replace(/\.indd$/i,".pdf")), false); 

                  } 

              _pages = []; 

          } 

      //=================================================================== Can I put progress bar in here?

                 var counter = new Window("palette");

                 counter.prompt = counter.add("statictext",[0,0,80,20]);

                 counter.show();

                 var cells = app.activeDocument.allCellStyles;

                 for(var i = cells.length-1; i > 0; i--){

                 counter.prompt.text = String(i);

                 cells[i].verticalJustification = VerticalJustification.bottomAlign;

                 }

                 counter.close();

       

      //===================================================================

       

       

      app.findTextPreferences = null;

       

      alert("Done.");

       

      thanks

       

      Harvey

        • 2. Re: How can add a progress bar into script?
          hasvi Level 1

          Hi harvey,

           

          you can add this code in "front or back" part of your script, try this

           

          main();

          function main(){

                var progress_win = new Window ("palette");

          var progress = progress_bar(progress_win, 2, 'Processing ... Completed');

              delay(1);

                progress.value = progress.value+1;

              delay(1);

              progress.parent.close();

              }

          // delay function found here

          //found here http://www.wer-weiss-was.de/theme157/article1143593.html

            function delay(prmSec){

            prmSec *= 1000;

            var eDate = null;

            var eMsec = 0;

            var sDate = new Date();

            var sMsec = sDate.getTime();

            do {

            eDate = new Date();

            eMsec = eDate.getTime();

            } while ((eMsec-sMsec)<prmSec);

            }

          /**

          * Taken from ScriptUI by Peter Kahrel

          *

          * @param  {Palette} w    the palette the progress is shown on

          * @param  {[type]} stop [description]

          * @return {[type]}      [description]

          */

          function progress_bar (w, stop, labeltext) {

          var txt = w.add('statictext',undefined,labeltext);

          var pbar = w.add ("progressbar", undefined, 1, stop);

          pbar.preferredSize = [300,20];

          w.show ();

          return pbar;

          }

           

          by

          hasvi

          • 3. Re: How can add a progress bar into script?
            Chinnadk Level 4

            Hi Harvey,

             

            Try this,

             

            var doc = app.documents;
            app.findTextPreferences = null;
            app.findTextPreferences.underline = true;
            
            for(var i=0;i<doc.length;i++)
            {
                    var found = doc[i].findText();
                    var _pages = [];
                    for(var j=0;j<found.length;j++)
                    {
                            var txfms = found[j].texts[0].parentTextFrames;
                            for(var k=0;k<txfms.length;k++)
                            {
                                    _pages.push(txfms[k].parentPage.name);
                                }
                        }
                    for(var j=0;j<_pages.length;j++)
                    {
                            if(_pages[j] === _pages[j-1])
                            {
                                    _pages.splice(j,1);
                                }
                        }
                    if(_pages.length != 0)
                    {
                            app.pdfExportPreferences.pageRange = _pages.toString();
                            doc[i].exportFile(ExportFormat.PDF_TYPE, new File(doc[i].fullName.toString().replace(/\.indd$/i,".pdf")), false);
                        }
                    _pages = [];
                }
            
            
                var counter = new Window("palette");
                counter.prompt = counter.add("statictext",[0,0,80,20]);
                counter.show();
                var cells = app.activeDocument.allCellStyles;
               
                var w = new Window('palette'); 
                w.pbar = w.add('progressbar', undefined, 0, cells.length); 
                w.pbar.preferredSize.width = 300; 
                w.show();
                w.pbar.value = 0;
               
                for(var i = cells.length-1; i > 0; i--)
                {
                    w.pbar.value += 1;
                    counter.prompt.text = String(i);
                    cells[i].verticalJustification = VerticalJustification.bottomAlign;
                }
                counter.close();
            
            
            app.findTextPreferences = null;
            
            alert("Done.");
            

             

            Regards,

            Chinna

            • 4. Re: How can add a progress bar into script?
              HarveyLiu Level 1

              Hi, Chinna

               

              thank you for your help

               

              but the progress bar not really work

               

              may be the progress bar need to put at beginning

               

              Harvey