4 Replies Latest reply on Nov 4, 2014 3:04 AM by [Jongware]

    this script how to ensure two conditions

    hamdifem Level 1

      page number pairs and object style how do you spell

       

      var d = app.activeDocument;
          for(i = 0; i < d.pages.length; +2) {
              p = d.pages.item(i);
              if(p && p.isValid) {
      pi = p.pageItems;
      for(k = 0; k < pi.length; ++k) {    
      it = pi[k];    
          app.findGrepPreferences = app.changeGrepPreferences = null;  
          app.findGrepPreferences.findWhat = "(.+?) - (\\d+)";  
          found = app.activeDocument.findGrep (true); 
          for (j = 0; j < found.length; j++) 
          { 
              found[j].select(); 
              if(i % 2 == 0) 
              //if(i % 2 == 0 && found[j].parentTextFrames[0].appliedObjectStyle.name == "AA1") 
              if(found[j].parentTextFrames[0].appliedObjectStyle.name == "AA1")
              { 
                  found[j].texts[0].select(); 
                  //found[j].texts[0].appliedParagraphStyle = "myParaStyle"; 
                  app.changeGrepPreferences.changeTo = "$2 / $1";
                  app.selection[0].changeGrep(); 
                  } 
              } 
          app.findGrepPreferences = app.changeGrepPreferences = null;        
      }
      } 
      }
      }
      
        • 1. Re: this script how to ensure two conditions
          Sajeev Sridharan Level 4

          Try this,

           

              app.findGrepPreferences = app.changeGrepPreferences = null;    
              app.findGrepPreferences.findWhat = "(.+?) - (\\d+)";    
              found = app.activeDocument.findGrep (true);   
              for (j = 0; j < found.length; j++)   
              {   
                  found[j].select();   
                  if(found[j].parentTextFrames[0].parentPage.name % 2 == 0 && found[j].parentTextFrames[0].appliedObjectStyle.name == "AA1")  
                  {   
                      found[j].texts[0].select();   
                      app.changeGrepPreferences.changeTo = "$2 / $1";  
                      app.selection[0].changeGrep();   
                      }   
                  }   
              app.findGrepPreferences = app.changeGrepPreferences = null;          
          
          

           

          Vandy

          • 2. Re: this script how to ensure two conditions
            hamdifem Level 1

            why is that starting from the last page to the beginning enumerates

             

            sno1=0;

            app.findGrepPreferences = app.changeGrepPreferences = null;     

                app.findGrepPreferences.findWhat = "(.+?) - (\\d+)";     

                found = app.activeDocument.findGrep (true);    

                for (j = 0; j < found.length; j++)    

                {    

                    found[j].select();    

                    if(found[j].parentTextFrames[0].parentPage.name % 2 == 0 && found[j].parentTextFrames[0].appliedObjectStyle.name == "AA1")   

                    {    

                        found[j].texts[0].select();    

                        app.changeGrepPreferences.changeTo = "$1 - "+ (++sno1);   

                        app.selection[0].changeGrep();    

                        }    

                    }    

                app.findGrepPreferences = app.changeGrepPreferences = null;

            • 3. Re: this script how to ensure two conditions
              Sajeev Sridharan Level 4

              Change this line:

               

              for (j = 0; j < found.length; j++)   


              to

               

              for (j = found.length-1; j >=0 ; j--)   

               

              Vandy

              • 4. Re: this script how to ensure two conditions
                [Jongware] Most Valuable Participant

                vandy88 wrote:

                 

                Change this line:

                 

                for (j = 0; j < found.length; j++)   


                to

                 

                for (j = found.length-1; j >=0 ; j--)  

                 

                While that should work, it makes far more sense to simply set the argument of findGrep to 'false': Text: findGrep