7 Replies Latest reply on Oct 31, 2014 9:22 AM by Sajeev Sridharan

    Can you help me with this script

    hamdifem Level 1

      with the following command in the master page object style (AA1) I'm active

       

      var d = app.activeDocument;
      function myFindObjStyle(a) {
      var x, i;
      for(i = 0; i < a.length; ++i) {
      if(i == a.length - 1) {
      x = (x ? x : d).objectStyles.item(a[i]);
      if(!x || !x.isValid) return null;
      } else {
      x = (x ? x : d).objectStyleGroups.itemByName(a[i]);
      if(!x || !x.isValid) return null;
      }
      }
      return x.isValid ? x : null;
      }
      function paragraphByNesneStilWp(stil) {
      var tests = [], i, j, it, p, finded;
      for(i = 0; i < d.pages.length; ++i) {
      p = d.pages.item(i);
      if(p && p.isValid) {
      pi = p.pageItems;
      finded = false;
      for(j = 0; j < pi.length; ++j) {
      it = pi[j];
      if(it && it.appliedObjectStyle == stil) {
      finded = true;
      tests.push({pr: it, sn: i});
      break;
      }
      }
      if(!finded) {
      pi = p.masterPageItems;
      for(j = 0; j < pi.length; ++j) {
      it = pi[j];
      if(it && it.appliedObjectStyle == stil) {
      tests.push({pr: it.override(p), sn: i});
      break;
      }
      }
      }
      }
      }
      return tests;
      }
      var FobjectStyle, objectss;
      FobjectStyle = myFindObjStyle(["AA1"]);
      if(!FobjectStyle) {
              alert("no style");
      }
      objectss = paragraphByNesneStilWp(FobjectStyle); 
      
      

       

      I want that my

      two pages increasing (Exercise - 1  Exercise - 1  Exercise - 2  Exercise - 2  ...)

      as the picture

      Can I place into the script

       

      Başlıksız-2.jpg

        • 1. Re: Can you help me with this script
          Sajeev Sridharan Level 4

          Try this,

           

          var d = app.activeDocument;  
          k=1;
          function myFindObjStyle(a) {  
          var x, i;  
          for(i = 0; i < a.length; ++i) {  
          if(i == a.length - 1) {  
          x = (x ? x : d).objectStyles.item(a[i]);  
          if(!x || !x.isValid) return null;  
          } else {  
          x = (x ? x : d).objectStyleGroups.itemByName(a[i]);  
          if(!x || !x.isValid) return null;  
          }  
          }  
          return x.isValid ? x : null;  
          }  
          function paragraphByNesneStilWp(stil) {  
          var tests = [], i, j, it, p, finded;  
          for(i = 0; i < d.pages.length; ++i) {  
          p = d.pages.item(i);  
          if(p && p.isValid) {  
          pi = p.pageItems;  
          finded = false;  
          for(j = 0; j < pi.length; ++j) {  
          it = pi[j];  
          if(it && it.appliedObjectStyle == stil) {  
          finded = true;  
          tests.push({pr: it, sn: i});  
          break;  
          }  
          }  
          if(!finded) {  
          pi = p.masterPageItems;  
          for(j = 0; j < pi.length; ++j) {  
          it = pi[j];  
          if(it && it.appliedObjectStyle == stil) {  
          tests.push({pr: it.override(p), sn: i});  
          //pi[j].insertionPoints[0].contents="sajeev";
          break;  
          }  
          }  
          
          pi = p.pageItems;  
          for(j = 0; j < pi.length; ++j) {  
          it = pi[j];  
          if(it && it.appliedObjectStyle == stil) {  
              pi[j].select();
              if(i % 2 == 0)
              {
                  pi[j].insertionPoints[0].contents="Example " + (k);
              }
              else
              {
                  pi[j].insertionPoints[0].contents="Example " + (k);
                  k++;
              }
          break;  
          }  
          }  
          }  
          }  
          }  
          return tests;  
          }  
          var FobjectStyle, objectss;  
          FobjectStyle = myFindObjStyle(["AA1"]);  
          if(!FobjectStyle) {  
                  alert("no style");  
          }  
          objectss = paragraphByNesneStilWp(FobjectStyle);   
          

           

          Vandy

          • 2. Re: Can you help me with this script
            hamdifem Level 1

            thank you

            When I run the command a second time

            delete the text in the text frame rewrite

            I want to change the font and size

             

            pi = p.pageItems;   

            for(j = 0; j < pi.length; ++j) {   

            it = pi[j];   

            if(it && it.appliedObjectStyle == stil) {   

                var p;

                it.select(); 

                p = it.paragraphs[0]; // ????????????????????

                if(i % 2 == 0) 

                { 

                    p.contents="TEST - " + (k); 

                } 

                else 

                { 

                    p.contents="TEST - " + (k); 

                    k++; 

                } 

            p.appliedFont = "Swis721 Cn BT";

                p.pointSize = 30;

            • 3. Re: Re: Can you help me with this script
              Sajeev Sridharan Level 4

              Try this,

               

              var d = app.activeDocument;  
              k=1;
              function myFindObjStyle(a) {  
              var x, i;  
              for(i = 0; i < a.length; ++i) {  
              if(i == a.length - 1) {  
              x = (x ? x : d).objectStyles.item(a[i]);  
              if(!x || !x.isValid) return null;  
              } else {  
              x = (x ? x : d).objectStyleGroups.itemByName(a[i]);  
              if(!x || !x.isValid) return null;  
              }  
              }  
              return x.isValid ? x : null;  
              }  
              function paragraphByNesneStilWp(stil) {  
              var tests = [], i, j, it, p, finded;  
              for(i = 0; i < d.pages.length; ++i) {  
              p = d.pages.item(i);  
              if(p && p.isValid) {  
              pi = p.pageItems;  
              finded = false;  
              for(j = 0; j < pi.length; ++j) {  
              it = pi[j];  
              if(it && it.appliedObjectStyle == stil) {  
              finded = true;  
              tests.push({pr: it, sn: i});  
              break;  
              }  
              }  
              if(!finded) {  
              pi = p.masterPageItems;  
              for(j = 0; j < pi.length; ++j) {  
              it = pi[j];  
              if(it && it.appliedObjectStyle == stil) {  
              tests.push({pr: it.override(p), sn: i});  
              //pi[j].insertionPoints[0].contents="sajeev";
              break;  
              }  
              }  
              
              
              pi = p.pageItems;  
              for(j = 0; j < pi.length; ++j) {  
              it = pi[j];  
              if(it && it.appliedObjectStyle == stil) {  
                  pi[j].select();
                  pi[j].insertionPoints[0].appliedFont = "Swis721 Cn BT";
                  pi[j].insertionPoints[0].pointSize = 30;
                  if(i % 2 == 0)
                  {
                      pi[j].insertionPoints[0].contents="Test - " + (k);
                  }
                  else
                  {
                      pi[j].insertionPoints[0].contents="Test -  " + (k);
                      k++;
                  }
              break;  
              }  
              }  
              }  
              }  
              }  
              return tests;  
              }  
              var FobjectStyle, objectss;  
              FobjectStyle = myFindObjStyle(["AA1"]);  
              if(!FobjectStyle) {  
                      alert("no style");  
              }  
              objectss = paragraphByNesneStilWp(FobjectStyle);   
              
              

               

              Vandy

              • 4. Re: Can you help me with this script
                hamdifem Level 1

                When I run the command a second time

                remove and over it I wanted to write

                Adsız3.jpg

                • 5. Re: Re: Can you help me with this script
                  Sajeev Sridharan Level 4

                  If you are run the same script it wont give the result, try the below code,

                   

                      app.findGrepPreferences = app.changeGrepPreferences = null; 
                      app.findGrepPreferences.findWhat = "Example - "; 
                      found = app.activeDocument.findGrep (true);
                      for (j = 0; j < found.length; j++)
                      {
                          found[j].select();
                          if(found[j].parentTextFrames[0].appliedObjectStyle.name == "AA1")
                          {
                              found[j].texts[0].select();
                  //            found[j].texts[0].appliedParagraphStyle = "myParaStyle";
                  //If you want to change the style then create a paragraph style according to your requirement and mention your style name in the above line
                              app.changeGrepPreferences.changeTo  = "Test - "; 
                              app.selection[0].changeGrep();
                              }
                          }
                      app.findGrepPreferences = app.changeGrepPreferences = null; 
                  

                   

                   

                  Vandy

                  • 6. Re: Can you help me with this script
                    hamdifem Level 1

                    "Test - 1"   >  I want to change the locations of the text  >  "1 - Test"

                     

                     

                    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].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;

                    • 7. Re: Can you help me with this script
                      Sajeev Sridharan Level 4

                      Try this,

                       

                       

                      app.findGrepPreferences = app.changeGrepPreferences = null; 

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

                      app.findGrepPreferences.appliedParagraphStyle= "myParaStyle"; 

                      app.changeGrepPreferences.changeTo = "$2 - $1";

                      app.activeDocument.changeGrep();

                      app.findGrepPreferences = app.changeGrepPreferences = null;


                      Vandy