0 Replies Latest reply on Oct 22, 2016 3:06 AM by Obi-wan Kenobi

    Code to be evaluated! [001]

    Obi-wan Kenobi Adobe Community Professional

      Hi all,

       

      The beginning is some text with "English" words lists followed by their "French" translation.

      The 2 lists are originally styled with 2 para styles ("English" and "French").

      Of course, in each double list, I've the English/French Words same number. Here: 7/7, 4/4 and 3/3.

       

      About my process, I've temporarily inserted (with 2 regex):

      @ at the "English" para beginning;

      % at the "French" para beginning;

       

      (not actually in the script).

       

      I want to do this (the numbers are only here for more visibility):

       

      Before:

       

      Capture d’écran 2016-10-20 à 21.36.10.png

       

      After:

       

      Capture d’écran 2016-10-20 à 21.36.46.png

       

      The code I've written uses a "while" loop.

       

      It works fine but it doesn't seem to me really orthodox! 

       

      Surely a better way to imagine the process and the [JS] code!  Thanks in advance!

       

       

      app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'English/French"');
        
      function main()
      {  
      
      
      var myDoc = app.activeDocument;
      var myCondition = "XX";
      app.findGrepPreferences = app.changeGrepPreferences = null;  
      app.findGrepPreferences.findWhat = "(?s)(^@([^%]+?$))([^%]+)(%([^%]+))";
      app.findGrepPreferences.appliedConditions = [myCondition];
      myFound = myDoc.findGrep( );
      
      
      while (myFound != 0)
      {
      app.findGrepPreferences = app.changeGrepPreferences = null;  
      app.findGrepPreferences.findWhat = "(?s)(^@([^%]+?$))([^%]+)(%([^%]+))";
      app.findGrepPreferences.appliedConditions = [myCondition];
      myFound = myDoc.findGrep( );
      
      
      app.changeGrepPreferences.changeTo = "$2 / $5$3";
      myDoc.changeGrep();
      
      
      app.findGrepPreferences = app.changeGrepPreferences = null;  
      app.findGrepPreferences.findWhat = "^\\r";
      app.findGrepPreferences.appliedConditions = [myCondition];
      app.changeGrepPreferences.changeTo = "";
      myDoc.changeGrep( );
      }
      
      
      app.findGrepPreferences = app.changeGrepPreferences = null;  
      app.findGrepPreferences.appliedConditions = [myCondition];  
      app.changeGrepPreferences.appliedConditions = []; 
      myDoc.changeGrep( );
      
      
      }
      

       

       

      (^/)