6 Replies Latest reply on Jun 24, 2016 11:02 AM by cbishop01

    Help with Progress Bar.

    cbishop01 Level 2

      Hi I've tried to add a few different progress bars to this script and i keep getting errors.  Can someone help please?   I have it right now placed at the beginning of the Script but i've had it at the end as well with no luck.  Below is the Code. 

         #targetengine "AutoStartScript" 
         
      // Save and open information      
          app.addEventListener( "beforeSave" , doTextFrameOnPageOne );  
          app.addEventListener( "beforeSave" , doZeroPoint );
          app.addEventListener( "afterOpen" , doZeroPoint );
      
      // -----------------> Progress Bar<-------------------    
          app.scriptPreferences.enableRedraw = true
          var found = Array(50);
          var w = new Window('palette');
              w.add ("progressbar", undefined, start, stop);
              w.pbar = w.add('progressbar', undefined, 0, found.length);
              w.pbar.preferredSize.width = 300;
              w.show();
          for(var i = found.length-1;i>-1;i--){
              w.pbar.value = found.length-i;
              $.sleep(20);
              }
          
       // Reset the Zero Point on documents.   
          function doZeroPoint()
              {
                 app.documents[0].zeroPoint = [0,0]; 
              
            
      // Create New Layer      
          function addLayer(doc, name) {  
          try{  
                  var layer = doc.layers.itemByName(name);  
                  if(layer && layer.isValid) {  
                           return layer;  
                      } else {  
                  var myLayer = doc.layers.add();  
                  myLayer.name = name; 
                  
                      return myLayer;  
              }  
            } catch(e) {  
           }  
          }  
            
      // Create Text Frame      
          function addTextFrame(doc, layer, name) {  
              var myBlendingSettings = { blendMode : BlendMode.OVERLAY };        
              var myTransparencySettings = { blendingSettings : myBlendingSettings };     
                
              var tf = doc.textFrames.itemByName(name);  
              if(tf && tf.isValid) {        
                  tf.remove();  
              }  
              tf = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {name: name, fillColor :"Yellow", fillTint: 20, transparencySettings : myTransparencySettings, geometricBounds: ['0in','-5.45in','1.45in','-.75in'] });        
                    return tf;  
          }  
            
      // Create Table      
          function addTable(tf) {  
              var myTable = tf.texts[0].tables.add        
                  (        
                     {         
                       // Number of Rows and Columns.      
                        bodyRowCount : 6 ,         
                        columnCount : 2         
                                
                   }        
              );       
            
          return myTable;  
              }  
            
            
          function addVariable(doc, name, value) {  
              var v = doc.textVariables.itemByName(name);  
              if(v && v.isValid)  
                  return;  
            
              v = doc.textVariables.add({name:name, variableType:VariableTypes.CUSTOM_TEXT_TYPE});  
              v.variableOptions.contents =  value;      
          }  
            
            
          function doTextFrameOnPageOne(event)        
           {       
              var doc = event.target;     
              if(!(doc && doc.constructor.name == "Document")) {  
                  return;  
              }  
                  
      // Create New Layer   
              var myLayer = addLayer(doc, "SaveInfo");  
                 
              var columnOneContentsArray = [                  
                   
                   "Document:" ,        
                   "User Name:",       
                   "Computer Name:",      
                   "Date Modified:",            
                   "Date Output:",      
                   "Date Created:",      
                   "Output Date:"        
              ];        
                      
              var columnTwoContentsArray = [     
                  ];     
                         
              var tf = addTextFrame(doc, myLayer, "SaveInfo");  
      // Table Properties
              var myTable = addTable(tf);  
                  setColumnWidthsAndAlignments(myTable)  
          function setColumnWidthsAndAlignments(tableObj)  
             {  
              var myWidths=[1.35, 3.32];  
              var myAlignments=[Justification.LEFT_ALIGN,Justification.LEFT_ALIGN];  
              var numberOfColumns=tableObj.columns.count();  
              for (c=0;c<numberOfColumns;c++)  
             {  
                  myTable.columns[c].width=myWidths[c];  
                  myTable.columns[c].cells.everyItem().texts.everyItem().justification=myAlignments[c];  
             }  
            }       
      // Create New Text Variables and Variable Options.
              var md = doc.textVariables.itemByName("Output Date");
                  md.variableOptions.format = "MMMM dd, yyyy hh:mm a";
              var md = doc.textVariables.itemByName("Creation Date");
                  md.variableOptions.format = "MMMM dd, yyyy hh:mm a";
                  tv = doc.textVariables.item("Users Name");    
                  !tv.isValid && tv = doc.textVariables.add({name:"Users Name", variableType:VariableTypes.CUSTOM_TEXT_TYPE});            
                  tv.variableOptions.contents =  String( getAppUserName() );  
                  tvL = doc.textVariables.item("CLN");   
                  !tvL.isValid && tvL = doc.textVariables.add({name:"CLN", variableType:VariableTypes.CUSTOM_TEXT_TYPE});    
                  tvL.variableOptions.contents =  String( getLogInUserName() ); 
                
                         
      // Placing Text variable information in tables             
              var R1, R2, R3, R4, R5, R6;       
                       
                  myTable.columns[0].contents = columnOneContentsArray;        
                  myTable.columns[1].contents = columnTwoContentsArray;        
              var cell0OfColumn2insertionPoint1 = myTable.columns[1].cells[0].insertionPoints[0];       
              var R1 = cell0OfColumn2insertionPoint1.textVariableInstances.add(LocationOptions.AFTER, cell0OfColumn2insertionPoint1);            
                  R1.associatedTextVariable = doc.textVariables.itemByName("File Name");       
              var cell1OfColumn2insertionPoint1 = myTable.columns[1].cells[1].insertionPoints[0];      
              var R2 = cell1OfColumn2insertionPoint1.textVariableInstances.add(LocationOptions.AFTER, cell1OfColumn2insertionPoint1);    
                  R2.associatedTextVariable = doc.textVariables.itemByName("Users Name")         
              var cell2OfColumn2insertionPoint1 = myTable.columns[1].cells[2].insertionPoints[0];          
              var R3 = cell2OfColumn2insertionPoint1.textVariableInstances.add(LocationOptions.AFTER, cell2OfColumn2insertionPoint1);            
                  R3.associatedTextVariable = doc.textVariables.itemByName("CLN");         
              var cell3OfColumn2insertionPoint1 = myTable.columns[1].cells[3].insertionPoints[0];        
              var R4 = cell3OfColumn2insertionPoint1.textVariableInstances.add(LocationOptions.AFTER, cell3OfColumn2insertionPoint1);            
                  R4.associatedTextVariable = doc.textVariables.itemByName("Modification Date");       
              var cell4OfColumn2insertionPoint1 = myTable.columns[1].cells[4].insertionPoints[0];       
              var R5 = cell4OfColumn2insertionPoint1.textVariableInstances.add(LocationOptions.AFTER, cell4OfColumn2insertionPoint1);            
                  R5.associatedTextVariable = doc.textVariables.itemByName("Output Date");       
              var cell5OfColumn2insertionPoint1 = myTable.columns[1].cells[5].insertionPoints[0];      
              var R6 = cell5OfColumn2insertionPoint1.textVariableInstances.add(LocationOptions.AFTER, cell5OfColumn2insertionPoint1);            
                  R6.associatedTextVariable = doc.textVariables.itemByName("Creation Date");         
              }        
            
            
      //  Computer User Name          
              function getLogInUserName()        
           {        
                
               var userNameOSX = $.getenv("USER");        
               var userNameWindows = $.getenv("USERNAME");        
                      
                  if(userNameWindows == null){return userNameOSX}        
                  else{return userNameWindows};        
                      
              }        
      // Application Name           
              function getAppUserName() 
              {        
                  return app.userName;        
          }
      

      Thank you for any help you can give.  I got the above "Progress Bar" from ScriptUI for dummies I believe its from Peter.