7 Replies Latest reply on Mar 21, 2014 9:26 AM by Laubender

    multiple findTextPreferences in a loop

    LeftHead

      Hi

       

      I would like to make multiples finds to tag my characters (Italic, Bold, AllCaps, SmallCaps, Underline...). To do so, i'm creating an Array, trying to store my findTextPreferences and using it in a "for" loop.

       

      I've try different writing but nothing works.

       

      Store like this :

      caraFindPrefs[0][0] = "app.findGrepPreferences.fontStyle = 'Italic'"

      Use like that in the "for" loop :

      eval(caraFindPrefs[i][0]);

       

      Store like this :

      caraFindPrefs[0][0] = "fontStyle"

      caraFindPrefs[0][1] = "Bold";

      Use like that in the "for" loop :

      app.findGrepPreferences.eval(caraFindPrefs[i][0]) = caraFindPrefs[0][1];

      Or like that

      app.findGrepPreferences.caraFindPrefs[i][0] = caraFindPrefs[0][1];

      ...

       

      Do you have any advice to do this ?

       

      Seb

        • 1. Re: multiple findTextPreferences in a loop
          Kai Rübsamen Adobe Community Professional

          Hi,

           

          try the following lines:

           

           

          var curDoc = app.activeDocument;  
          
          var cStyleList = [ 
              ["Italic", "italic"], 
              ["Bold", "bold"] 
          ]; 
          
          for ( var j = 0; j < cStyleList.length; j++ ) { 
              app.findGrepPreferences = app.changeGrepPreferences = null;  
              app.findGrepPreferences.fontStyle = cStyleList[j][0];  
              app.changeGrepPreferences.appliedCharacterStyle = cStyleList[j][1];  
              curDoc.changeGrep();  
          } 
          
          app.findGrepPreferences = app.changeGrepPreferences = null;
          
          • 2. Re: multiple findTextPreferences in a loop
            LeftHead Level 1

            Hi Kai,

             

            Thanks... but unfortunately "no" :-)

             

            Your solution is obvious as long as you apply only fontStyle, but what I'm looking for is to manage in the same loop, the ".position" or ".underline", ".strikethru"... properties ?

            • 3. Re: multiple findTextPreferences in a loop
              Laubender Adobe Community Professional & MVP

              @LeftHand – then, how about working with the properties property?

              You could apply several properties in one go.

               

              var p = {
              
                  fontStyle : [ "Italic" , "Bold" ],
                  underline : [ true , false ]
              
                  };
              
              app.findGrepPreferences = null;
              
              app.findGrepPreferences.properties = {
                  fontStyle : p.fontStyle[1],
                  underline : p.underline[0]
                  };
              

               

              Don't know why you like to do it this way, but something like the above is possible.

               

              Also more directly and not so convoluted:

               

              app.findGrepPreferences = null;
              app.findGrepPreferences.properties = { fontStyle : "Bold", underline : true };
              

               

              Uwe

              • 4. Re: multiple findTextPreferences in a loop
                LeftHead Level 1

                Argh, I'm not explaining correctly :-)

                 

                I want to find all my Italics then all my Bolds then all my underline, then all my smallcaps... but group it in one "for" loop to spare some script lines (the script is ok with multiples findText but would like to optimise it).

                 

                Seb

                • 5. Re: multiple findTextPreferences in a loop
                  Laubender Adobe Community Professional & MVP

                  Smallcaps?


                  Not possible.

                  It's not a property of findTextPreferences or findGrepPreferences.

                  An omission of the team that wrote ExtendScript functionality for InDesign.

                   

                  For other property/value pairs you could build an array of objects:

                   

                  var myArray = 
                      [
                          {fontStyle : "Italic"},
                          {fontStyle : "Bold"},
                          {underline : true }
                  
                      ];
                  
                  var myResultArray = [];
                  
                  var myScope = app.activeDocument;
                  
                  for(var n=0; n<myArray.length; n++){
                  
                      app.findTextPreferences = app.changeTextPreferences = null;
                      app.findTextPreferences.properties = myArray[n];
                      myResultArray[n] = myScope.findText(false);
                  
                      };
                  

                   

                   

                  Uwe

                  • 6. Re: multiple findTextPreferences in a loop
                    LeftHead Level 1

                    Yes, will try this !

                     

                    For smallcaps :

                     

                    app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;

                     

                     

                    • 7. Re: multiple findTextPreferences in a loop
                      Laubender Adobe Community Professional & MVP

                      Thank you, missed that…
                      Ah. It seems it's Friday.

                       

                      Uwe