4 Replies Latest reply on May 5, 2015 4:03 PM by Qwertyfly...

    loading bar and MATH.CEIL

    Zantcor

      Hey guys,

       

      I've wrote a script that I'm trying to get to work where it shows loading bars for all the different script and templates.  The reason for this is that there are so many files that this can take a little while to do and this will let the user see something working other then illustrator just locking up for a little while.  Below is one section of the code that will run if you want to try and test it.  Maybe I'm just using MATH.ceil wrong.

       

      #target illustrator
      
      //Script Name: Fill Template Arrays
      //Script Version: 1.0.0
      //Script Description:   1.  This script will populate all the arrays that are used by the template scripts  
      //                                    2.  This process used to have to load when the script for each template script was ran
      //                                    3.  This should reduce the total amount of time needed to do the artists jobs
      //Script Parent: Script Pallet
      //Script Author: Zantcor
      //Scripted Created: April 30th, 2015
      //Script last edited:
      //Script edited by:
      //Script Owner: Zantcor
      
      //Progress Bar to show loading of templates
      
      var win = new Window("palette", "Loading Templates and Prepareing Scripts");   
      win.pnl = win.add("panel",undefined, "Script Progress");  
      
      totalprogBar = win.pnl.add('progressbar', [20, 35, 410, 60], 0, 100); 
      totalprogBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], " Total - Not Loading");  
      
      totesprogBar = win.pnl.add('progressbar', [20, 35, 410, 60], 0, 100);
      totesprogBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], " Totes - Not Loading");
      
      UmbrellaprogBar = win.pnl.add('progressbar', [20, 35, 410, 60], 0, 100); 
      UmbrellaprogBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], " Umbrella - Not Loading");
      
      CalendarprogBar = win.pnl.add('progressbar', [20, 35, 410, 60], 0, 100); 
      CalendarprogBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], " Calendar - Not Loading");  
        
      win.show();  
        
        getToteTempNames ()  
      
          alert('Done!');   
      
      
      function getToteTempNames()
      {  
          
          //Replace this address for the "toteTempPath" to the folder that has all the templates it in it, then the for loop will place them all
          //into a radio button array for the user to choose which one they want.  This updates everytime that this script is ran so if
          //one if removed or added it will show up reducing the amount of required time needed to update the script.
          //when replaced make sure to change the \ marks to / marks or it will not work.
          
        var toteTempPath = Folder ("S:/Art/ArtDept/  Vitronic Master Templates/STE2 Templates/TOTES & BAGS");   
        var toteTempFiles = toteTempPath.getFiles();  
        var TotenamesArr = [];  
        for(var i=0; i<toteTempFiles.length; i++)
        {  
        var thisToteFile = toteTempFiles[i];  
        TotenamesArr.push(thisToteFile.displayName);
        
      var totepercent = MATH.ceil (toteTempFiles.length / [i]);
      var totetempname = toteTempFiles[i];
      
      totesprogBar.value = totepercent
      totesprogBarLabel.text = ("Loading Totes - " + totesprogBar.value+"%" + "     filename: "  + totetempname); 
      
                  totalprogBar.value = 56
                  totalprogBarLabel.text = ("TOTAL - " + totalprogBar.value+"%");  
      
      }
      
        return TotenamesArr;  
      }  
      
        • 1. Re: loading bar and MATH.CEIL
          Qwertyfly... Level 4

          Not tested anything. But MATH.ceil should be Math.ceil.

          in ESTK Math will be red. MATH will not.

          also you don't need i to be [i] in that line. but it should not matter

          • 2. Re: loading bar and MATH.CEIL
            Zantcor Level 1

            Your correct about the Math vs MATH but it's still not updating correctly.  What am I missing?

             

            function getToteTempNames()
            {  
                
                //Replace this address for the "toteTempPath" to the folder that has all the templates it in it, then the for loop will place them all
                //into a radio button array for the user to choose which one they want.  This updates every time that this script is ran so if
                //one if removed or added it will show up reducing the amount of required time needed to update the script.
                //when replaced make sure to change the \ marks to / marks or it will not work.
                
              var toteTempPath = Folder ("S:/Art/ArtDept/  Vitronic Master Templates/STE2 Templates/TOTES & BAGS/");   
              var toteTempFiles = toteTempPath.getFiles();  
              var TotenamesArr = [];  
              for(var i=0; i<toteTempFiles.length; i++)
              {  
              var thisToteFile = toteTempFiles[i];  
              TotenamesArr.push(thisToteFile.displayName);
              
            var totepercent = Math.ceil ([i] / toteTempFiles.length);
            var totetempname = toteTempFiles[i];
            
            while (totepercent < 100)
            {
                
            totesprogBar.value = totepercent
            totesprogBarLabel.text = ("Loading Totes - " + totesprogBar.value+"%" + "     filename: "  + totetempname); 
            
                        totalprogBar.value = 32
                        totalprogBarLabel.text = ("TOTAL - " + totalprogBar.value+"%");
                        
                        if (totesprogBar.value == 100)
                        {
                            var loadtote = "done"
                            }
            }
            }
            

             

             

            Not trying to get anyone to write the code, just need someone to point me in a general direction.  There isn't that much information on progress bars that I can find.

             

            I'm trying to get it to show the % done and the file that it is currently loading but it locks up at 0% and doesn't update.  I tried adding a w.show() inside the while (totepercent < 100) but it throws an error since the window is open already and if I close and reopen it then it starts over.

            • 3. Re: loading bar and MATH.CEIL
              Qwertyfly... Level 4

              progress bar is set from 0 to 100

              so you need to divided that in to a number of segments

              20 files = 20 segments of 5 progress units

              so for each file processed you set progress bar value to (i + 1) * 5

              i + 1 due to it starting at 0.

               

              I think that's all correct but don't hold me to it, you will need to test...

              • 4. Re: loading bar and MATH.CEIL
                Qwertyfly... Level 4

                and to be accurate you may want to only use Math.ceil for the progress bars text, and not for value.