4 Replies Latest reply on Mar 2, 2017 7:48 AM by Obi-wan Kenobi

    Code to be evaluated! [015] Text Column Break! …

    Obi-wan Kenobi Adobe Community Professional

      Hi all!

       

      This code has a problem on the "rage" definition! … And I don't find why!! 

       

      app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Column Jump! …");
      
      
      function main()
          {       
              var myDoc = app.activeDocument,
              myStories = myDoc.stories.everyItem().getElements(),
              S = myStories.length,
              myCharStyle = myDoc.characterStyles.item("Red");
              for (var s = 0; s < S; s++) {
                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  app.findGrepPreferences.findWhat = "~M";
                  myColumnBreaks = myStories[s].findGrep();
                  myStories[s].characters.itemByRange(0, myColumnBreaks[0].index).appliedCharacterStyle = myCharStyle;
              }
              app.findGrepPreferences = null;
          }
      

       

      Thanks for help! 

       

      (^/)

        • 1. Re: Code to be evaluated! [015] Text Column Break! …
          Loic.Aigon Adobe Community Professional

          Nothing really problematic to me at first sight. You may not want to set the grep find preferences every loop though.

           

          app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Column Jump! …");  
            
            
          function main()  
          {         
            var myDoc = app.activeDocument,  
            myStories = myDoc.stories.everyItem().getElements(),  
            S = myStories.length,  
            myCharStyle = myDoc.characterStyles.itemByName("Red");  
          
            app.findGrepPreferences = app.changeGrepPreferences = null;  
            app.findGrepPreferences.findWhat = "~M";  
          
            for (var s = 0; s < S; s++) {  
            myColumnBreaks = myStories[s].findGrep();  
            myColumnBreaks.length>0 && myStories[s].characters.itemByRange(0, myColumnBreaks[0].index).appliedCharacterStyle = myCharStyle;  
            }  
            app.findGrepPreferences = null;  
          }  
          

           

          what's the issue exactly ?

          1 person found this helpful
          • 2. Re: Code to be evaluated! [015] Text Column Break! …
            Obi-wan Kenobi Adobe Community Professional

            Hi Loïc,

             

            You're right!

             

            I've just fixed it with:

             

            if (myColumnBreaks.length !== 0) myStories[s].characters.itemByRange(0, myColumnBreaks[0].index-1).appliedCharacterStyle = myCharStyle;
            

             

            … because there's a story on master pages!

             

            But I prefer yours:

             

            myColumnBreaks.length>0 && myStories[s].characters.itemByRange(0, myColumnBreaks[0].index).appliedCharacterStyle = myCharStyle;    
            

             

            … And you're totally right about to set the Grep find prefs out of the loop!

             

            Thanks! 

             

            (^/)

            1 person found this helpful
            • 3. Re: Code to be evaluated! [015] Text Column Break! …
              Loic.Aigon Adobe Community Professional

              Hi

               

              … because there's a story on master pages!

               

              Then you should be concerned by

               

              app.findChangeGrepOptions

               

              But I prefer yours:

              Not an absolute. Think it avoids an internal scope (if).

               

              … And you're totally right about to set the Grep find prefs out of the loop!

              It just doesn't make sense.

              • 4. Re: Code to be evaluated! [015] Text Column Break! …
                Obi-wan Kenobi Adobe Community Professional

                Loïc,

                 

                I could but I could have "blank" pages with empty story among the current pages too. So I prefer your way!

                Yes, I often forget this point! Use yours is, for my little brain, a better writing to debug a script (in this case).

                This is, imho, "intellectually", more interesting!

                 

                Thanks for all! I'm always a newbie but I make efforts! Aha!

                 

                (^/)