0 Replies Latest reply on Aug 29, 2016 10:13 AM by Obi-wan Kenobi

    Remove a Column in Tab Text …

    Obi-wan Kenobi Adobe Community Professional

      Hi All,

       

      How are you today? 

       

      My last night game:

      How to remove a "text-column" in tab text? … and how to do it with [JS] just entering the number of the column to be deleted in an UI?

       

      A special mention to Peter Kahrel for his amazing pdf on ScriptUI [revision in may 2016]:  ScriptUI for dummies | Peter Kahrel 

       

      Maybe the script I wrote below is not really "orthodox" but it works nice playing with Grep researches.

      If (surely) better, tell me [totally appreciated]!

       

      Actually, the script works on text selection without UI:

      Capture d’écran 2016-08-19 à 13.18.41.png

      Capture d’écran 2016-08-19 à 13.19.25.png

      Capture d’écran 2016-08-19 à 13.20.06.png

       

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;        
      app.doScript        
          (        
          main,        
          ScriptLanguage.JAVASCRIPT,        
          [],        
          UndoModes.ENTIRE_SCRIPT,        
          "Remove a Column in Tab Text!"        
          );        
              
      function main()        
      {        
          var myParagraphs = app.selection[0].paragraphs;  
        
          for (var i = 0; i < myParagraphs.length; i++){  
                
          app.findGrepPreferences = app.changeGrepPreferences = null;  
            
          //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------      
          app.findGrepPreferences.findWhat = /(?s)^([^\t\r]*(\t|$)){3}\K(?1)/.source;   //  Define the colum number as: 0, for the column 1; 1, for the column 2; 2, for the column 3 …  
          //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------      
            
          app.changeGrepPreferences.changeTo = "";
          
          }
      
      
          app.selection[0].changeGrep();  
      
      
          for (var i = 0; i < myParagraphs.length; i++){  
        
          app.findGrepPreferences = app.changeGrepPreferences = null;  
          app.findGrepPreferences.findWhat = /\t+$/.source;  
          app.changeGrepPreferences.changeTo = "";
          
          }  
        
          app.selection[0].changeGrep();  
          app.findGrepPreferences = app.changeGrepPreferences = null;  
        
      }  
      

       

       

      As I said, I would like to play with an UI [made with ScriptUI].

      The code I wrote to create it is:

       

       

      // Here's the UI
      
      
      var w = new Window ('dialog {alignChildren: "right"}', 'Remove a Column in Tab Text!');
        var group = w.add ('group');
        group.add ('statictext {text: "Remove the Column:" }');
        var myCol = group.add ("edittext", undefined, "1");
         myCol.minimumSize.width = 50;
          myCol.maximumSize.width = 50;
        myCol.active = true;
      
        var buttons = w.add ('group {alignment: "center"}');
        buttons.add ('button {text: "OK"}');
        buttons.add ('button {text: "Cancel"}');
      
      
      if (w.show() == 2) {  // Cancel pressed
        exit();
      }
      
      
      
      

       

       

      … But I'm always unable to continue: How to merge the 2 script parts!

       

      Last comment: as I said in my first script comment, "0" targets the first column, "1", the second, "2" the third, …

      in the UI, "1" (by default) will target the first column, "2", the second, "3" the third, …

      So, I will need a calculation! …

       

      Thanks a lot for any help and comment! 

       

      Next future step for me:

      Include the capacity to choose the target: selected text (as here), doc, story, para style and para style + "based on" para styles!  cool!