2 Replies Latest reply on Feb 6, 2014 2:55 PM by jason_clement

    Busy Cursor or Progress Bar

    jason_clement

      I have looked all around forums and links and am learning all sorts of things except for the one thing I need. I work for a publishing company and we produce a number of directories. I have modified the change/find script form adobe to pull these articles in from a tab-delimited text file. Everything works.

       

      Where I run into issues is trying to generate a progress bar or busy cursor. I have the progress bar from Peter Kahrel's Script UI for Dummies but can't seem to figure out how to determine the total number of lines in the file.

       

      Then I decided that the easiest thing would be to create a busy cursor and found this thread http://forums.adobe.com/thread/1109409. Problem solved... almost, I get an error stating "illegal use of reserved word import." This may be a Mac issue as the thread is a PC discussion.

       

      Could you help me figure out what I am missing? Solutions for Mac and PC are wonderful as I use CC on Mac at work and CS6 on PC at home.

       

      My code is below as I said the dirInput() function is working, with 5000+ entries it takes a little while to run so just need a progress bar or busy cursor. Thank you in advance. Jason

       

       

      import mx.managers.CursorManager;

      CursorManager.setBusyCursor();

       

       

       

       

       

       

      var doc = app.documents.item(0);

      var txtFrame = app.selection[0].parentStory;

      CursorManager.setBusyCursor();

       

       

      dirInput();

      CursorManager.removeBusyCursor();

       

       

      function dirInput(){

          var dirFile = File.openDialog("Choose the directory file you wish to import.");

          var txtLine, Lname, Fname, Phone, StreetNum, StreetName, HisEmploy, HerEmploy = null;

          Lcount = 0;

         

          if(dirFile != null){

              dirFile = File(dirFile);

              var myResult = dirFile.open("r",undefined,undefined);

             

              if (myResult == true){

       

       

                   //Loop through the find/change operations

                  do{

                      dirLine = dirFile.readln();

                      findTabArray = dirLine.split("\t")

                       //find options by tab

                      //>>> <tab 0> Last Name       <tab 1>        First Name       <tab 2>        Phone       <tab 3>        Street Number       <tab 4>        Street Name       <tab 5>        His Employment       <tab 6>        Her Employment

                      Lname = findTabArray[0]; //get the LastName - [0] tab              

                      Fname = findTabArray[1];  //get the First Name - [1] tab              

                      Phone = findTabArray[2];  //get  the Phone Number - [2] tabs               

                      StreetNum = findTabArray[3]; //get the Street Number- [3] tabs               

                      StreetName = findTabArray[4]; //get  the Streetname - [4] tabs               

                      HisEmploy = findTabArray[5];  //get His Employment - [5] tabs                              

                      HerEmploy = findTabArray[6]; //get Her Employment - [6] tabs

                     

                      //build and format the text line-by-line

                      txtLine = Lname + ", " + Fname;

                      txtLine = txtLine += "\t"; //add tab character

                      txtLine = txtLine + Phone;

                      txtLine = txtLine += "\n"; //add soft return

                      txtLine = txtLine + StreetNum + " " + StreetName;

                      txtLine = txtLine += "\n"; //add soft return

                      txtLine = txtLine + HisEmploy;

                      txtLine = txtLine += "\n"; //add soft return                         

                      txtLine = txtLine + HerEmploy;        

                      txtLine = txtLine += "\r"; //add paragraph return

       

       

                      txtFrame.insertionPoints.item(-1).contents = txtLine; //>>> Inserts the entry at the end of the text already in the text frame.

                      }while(dirFile.eof == false); //>>> completion of the do…while loop – in this case the loop runs until it reaches the end of the file (.eof); once eof is reached close the directory file.

                      dirFile.close();

                  }

              }

          }

       

       

      function progressbar(line) {

          var w = new Window ("dialog", "Export XML", undefined, {closeButton: false});

          w.add ("progressbar", undefined, 1, line);

          var w = new Window ('palette');

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

          w.pbar.preferredSize.width = 300;

          w.show();

          for (var i = 0; i < line; i++){

          w.pbar.value = i/300;

          $.sleep(20);

              }

          }

        • 1. Re: Busy Cursor or Progress Bar
          Jump_Over Level 5

          Hi,

           

          Use progress bar related to file.length (in bytes) and current position ( file.tell() as bytes offset).

          Example:

           

          // ... 
          // your code
          // ...
          
          dirFile = File(dirFile);
          // ... your code
          
          
          var end = dirFile.length;
          
                    // Progress bar -----------------------------------------------------------------------------------
                    var 
                              progressWin = new Window ("window", "Export XML"),
                              progressBar = progressWin.add ("progressbar", [12, 12, 450, 36], 0, end);
                    progressWin.show();
                    // Progress bar -----------------------------------------------------------------------------------
          
          do {
                    dirLine = dirFile.readln();
          // ... 
          // your code
          // ...
          
                    // Progress bar -----------------------------------------------------------------------------------
                              progressBar.value = dirFile.tell();
                    // Progress bar ----------------------------------------------------------------------------------- 
                    }
          while (dirFile.eof == false);
           
                    progressWin.close();
                    dirFile.close()
          

           

           

          Jarek

          1 person found this helpful
          • 2. Re: Busy Cursor or Progress Bar
            jason_clement Level 1

            Thank you Jarek! Below is my final script (just the parts that were changed). Jason

             

            function dirInput(){

                var dirFile = File.openDialog("Choose the directory file you wish to import.");

                var end = dirFile.length;

             

             

                if(dirFile != null){

                    dirFile = File(dirFile);

                    var myResult = dirFile.open("r",undefined,undefined);       

                   

                    if (myResult == true){

                      // Progress bar

                      progressbar ("Importing file",end);

                      // Progress bar  

                         //Loop through the find/change operations

                        do{

                            dirLine = dirFile.readln();

                            findTabArray = dirLine.split("\t")

                             //find options by tab

                            //>>> <tab 0> Last Name       <tab 1>        First Name       <tab 2>        Phone       <tab 3>        Street Number       <tab 4>        Street Name       <tab 5>        His Employment       <tab 6>        Her Employment

                            Lname = findTabArray[0]; //get the LastName - [0] tab              

                            Fname = findTabArray[1];  //get the First Name - [1] tab              

                            Phone = findTabArray[2];  //get  the Phone Number - [2] tabs               

                            StreetNum = findTabArray[3]; //get the Street Number- [3] tabs               

                            StreetName = findTabArray[4]; //get  the Streetname - [4] tabs               

                            HisEmploy = findTabArray[5];  //get His Employment - [5] tabs                              

                            HerEmploy = findTabArray[6]; //get Her Employment - [6] tabs

                           

                            //build and format the text line-by-line

                            txtLine = Lname + ", " + Fname;

                            txtLine = txtLine += "\t"; //add tab character

                            txtLine = txtLine + Phone;

                            txtLine = txtLine += "\n"; //add soft return

                            txtLine = txtLine + StreetNum + " " + StreetName;

                            txtLine = txtLine += "\n"; //add soft return

                            txtLine = txtLine + HisEmploy;

                            txtLine = txtLine += "\n"; //add soft return                         

                            txtLine = txtLine + HerEmploy;        

                            txtLine = txtLine += "\r"; //add paragraph return

             

             

                            txtFrame.insertionPoints.item(-1).contents = txtLine; //>>> Inserts the entry at the end of the text already in the text frame.

                            }while(dirFile.eof == false); //>>> completion of the do…while loop – in this case the loop runs until it reaches the end of the file (.eof); once eof is reached close the directory file.

            //~             progressWin.close();           

                        dirFile.close();

                        }

                    }

                }

             

             

            function progressbar(title,max) {

                var w = new Window ("dialog", title, undefined, {closeButton: false});

                w.add ("progressbar", undefined, 0, max);

                var found = new Array (max);

                var w = new Window ('palette');

                w.pbar = w.add ('progressbar', undefined, 0, found.length);

                w.pbar.preferredSize.width = 300;

                w.show();

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

                    w.pbar.value = i+1;

                    $.sleep(1);

                    }

                }