5 Replies Latest reply on Aug 2, 2016 11:27 PM by karthiks94217840

    Distribute tabbed longest word equally

    karthiks94217840 Level 2

      Hi Friends,

       

      I want a script that can distribute tabbed longest word equally. I need to find/change Two-Two lines only (minimum tab length "6.5 points").

       

      Please see my screenshot below:

       

      8.png

       

      Please see my below code:

       

      I have try this coding past one week, but i have not got answer. Please suggest friends.

       

      I received error from line number 33:

       

      app.findGrepPreferences = app.changeGrepPreferences = null;  
      app.findGrepPreferences.appliedParagraphStyle = "EXM";  
      app.findGrepPreferences.findWhat = "(.+)(\\r)(.+)(\\r)";
      var myFnd = app.activeDocument.findGrep(true);  
      
      for(var i=0; i<myFnd.length; i++)  
      {  
           
          var myFound = myFnd[i].select();  
           
          if(app.selection[0].lines.length > 1)  
          {  
              app.findGrepPreferences = app.changeGrepPreferences = null;  
              app.findGrepPreferences.findWhat = "\\t";  
              var myTabFind = app.selection[0].findGrep();  
              alert(myTabFind.length);
              
              myControlArray = new Array();        
              var myTabLength = myTabFind.length;
                   
                      var myStart = true;
                      if(myStart == true){  
                          for(n=0;n<myTabLength;n++){  
                              myControlArray[n] = 0;  
                              }  
                          }  
              }  
                 
                  for(n=0;n<myTabLength;n++){
                      var myIndex = myTabFind[n].index;
                      alert(myIndex);
                          if(n==0){
                              if((myFound.characters[myIndex].horizontalOffset)-myFound.characters[0].horizontalOffset > myControlArray[n] ){  
                                  myControlArray[n] = ((myFound.characters[myIndex].horizontalOffset) - myFound.characters[0].horizontalOffset) + 6.5;
                                  }  
                              }  
                           else{  
                               myEndPoint = myFound.characters[myTabFind[n].index].horizontalOffset;  
                               myStartPoint = myFound.characters[(myTabFind[n-1].index)+1].insertionPoints[0].horizontalOffset;  
                               if(myEndPoint - myStartPoint > myControlArray[n]){  
                                   myControlArray[n] = (myEndPoint - myStartPoint) + 6.5;  
                                   }  
                               }  
      
      
                  }  
          }  
      
      
      myTabStops = new Array();  
      for(i=0;i<myTabLength;i++){  
          if(i == 0){  
              myTabStops[i] = myControlArray[i];  
              }  
          else{  
              myTabStops[i] = myControlArray[i] + myTabStops[i-1];  
              }  
          }  
      myFound.tabStops.everyItem().remove();  
      for(i=0;i<myTabLength;i++){  
            myFound.tabStops.add({position:myTabStops[i]});  
           }  
      
      
      
      

       

       

      Thanks in Advance