18 Replies Latest reply on Jul 29, 2014 5:49 AM by Teetan VK

    How can find-change grep only on Masters

    Teetan VK Level 1

      Hi everyone,

       

      I want to find-change (multi line of options) only on master

       

      idea inspire by this line, but I am not going to find-change digit

       

      How can I find-change only in the master pages?

       

      thanks

       

      Teetan

        • 1. Re: How can find-change grep only on Masters
          Jump_Over Level 5

          Hi,

           

          Use same way as for digits is used: define a target and call it like: target.changeGrep()

          If your target is a collection of every stories on masterSpreads ==> you are proccessing find...change on masters in fact.

          i.e.

           

          mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();

          mTarget.changeGrep();

           

          You have to set all desired preferences and options of course.

           

          Jarek

          • 2. Re: How can find-change grep only on Masters
            Teetan VK Level 1

            Hi

             

            Jarek

             

            but what if I want change a long list of text or grep?

             

            Regard

             

            Teetan

            • 3. Re: How can find-change grep only on Masters
              Teetan VK Level 1

              Hi, Jarek

               

              I change it into this:

               

              app.doScript('main()', ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Find-change on master" );    

               

              function main(){

               

                catchOption = app.findChangeGrepOptions.includeMasterPages; 

                app.findChangeGrepOptions.includeMasterPages = true; 

                app.findGrepPreferences = changeGrepPreferences = null; 

                app.findGrepPreferences.findWhat = "USA"; 

               

               

              var 

                mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem(), 

                mTarget.changeGrep();

                mConFound = [], 

                len = mFound.length; 

               

               

                if (len && mFound[0].constructor.name == "Array") 

                 while (len-->0) 
                      mConFound = mConFound.concat(mFound[len]); 

               

                len = mConFound.length; 

                while (len-->0) { 

                 mConFound[len].contents = "Obama"; 

                } 

                app.findChangeGrepOptions.includeMasterPages = catchOption; 

               

              }

               

              but not work

               

              Teetan

              • 4. Re: Re: How can find-change grep only on Masters
                Jump_Over Level 5

                Hi,

                 

                What about this:

                 

                app.doScript('main()', ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Find-change on master" );
                function main(){
                app.findGrepPreferences = changeGrepPreferences = null;
                app.findGrepPreferences.findWhat = "USA";
                app.changeGrepPreferences.changeTo = "Obama";
                var
                mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem(),
                catchOption = app.findChangeGrepOptions.includeMasterPages;
                app.findChangeGrepOptions.includeMasterPages = true;
                mTarget.changeGrep();
                app.findChangeGrepOptions.includeMasterPages = catchOption;
                }
                

                 

                Jarek

                • 5. Re: How can find-change grep only on Masters
                  Teetan VK Level 1

                  Hi, Jarek

                   

                  Can you tell the solution, please!

                   

                  where I can put ot change this:

                   

                  mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();

                  mTarget.changeGrep();


                  Teetan

                  • 6. Re: Re: How can find-change grep only on Masters
                    Jump_Over Level 5

                    Hi,

                     

                    So the one from post no 4 is not a solution?

                     

                    Jarek

                    • 7. Re: How can find-change grep only on Masters
                      Teetan VK Level 1

                      Hi Jarek

                       

                      I am so blunt

                       

                      Can it be more specific?

                       

                      Teetan

                      • 8. Re: How can find-change grep only on Masters
                        Teetan VK Level 1

                        //---------------------------------------------------------------------------------------- --------------------------------------------------------------------------

                        Use same way as for digits is used: define a target and call it like: target.changeGrep()

                        If your target is a collection of every stories on masterSpreads ==> you are proccessing find...change on masters in fact.

                        i.e.

                         

                        mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();

                        mTarget.changeGrep();

                         

                        You have to set all desired preferences and options of course.

                        //---------------------------------------------------------------------------------------- ------------------------------------------------------------------------

                         

                        How can I do that?

                        • 9. Re: Re: How can find-change grep only on Masters
                          Jump_Over Level 5

                          Hm,

                           

                          code from a post no 4 is ready to run.

                          It finds each occurence of "USA" (can you see the line to edit?) on master pages of any opened document and change it to "Obama" (can you see the line to edit?).

                           

                          Jarek

                          • 10. Re: How can find-change grep only on Masters
                            Laubender Adobe Community Professional & MVP

                            Unless the text frame or the layer it is sitting in is locked.

                             

                            Or otherwise unavailable:
                            Like nested inside a group, a MSO, some other object, anchored to a text frame…

                             

                            Uwe

                            • 11. Re: How can find-change grep only on Masters
                              Teetan VK Level 1

                              Hi,

                               

                              Jeark

                               

                              We here made a misundersdanding:

                               

                              //---------------------------------------------------------------------------------------- ----------

                               

                              app.doScript('main()', ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Find-change on master" ); 

                               

                              function main(){ 

                              app.findGrepPreferences = changeGrepPreferences = null; 

                              app.findGrepPreferences.findWhat = "USA"; 

                              app.changeGrepPreferences.changeTo = "Obama"; 

                              app.findGrepPreferences.findWhat = "rocket"; 

                              app.changeGrepPreferences.changeTo = "sky"; 

                              app.findGrepPreferences.findWhat = "New York";                      // only work on this line

                              app.changeGrepPreferences.changeTo = "Losangeles"; 

                               

                              var 

                              mTarget = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem(), 

                              catchOption = app.findChangeGrepOptions.includeMasterPages; 

                              app.findChangeGrepOptions.includeMasterPages = true; 

                              mTarget.changeGrep(); 

                              app.findChangeGrepOptions.includeMasterPages = catchOption; 

                              }

                               

                              //---------------------------------------------------------------------------------------- ----------

                               

                              it will not work on a list

                               

                               

                               

                              //==========================================================

                               

                              Hi

                               

                              Jarek

                               

                              but what if I want change a long list of text or grep?

                               

                              Regard

                               

                              Teetan

                               

                              //==========================================================

                               

                              so it will only can change one thing right?

                               

                              thank you for your help, thank you so much

                               

                              Teetan

                              • 12. Re: How can find-change grep only on Masters
                                Jump_Over Level 5

                                Hi,

                                 

                                Agree, it is a misunderstanding at sure.

                                Jarek

                                • 13. Re: How can find-change grep only on Masters
                                  Kai Rübsamen Adobe Community Professional

                                  Teetan, don’t use code without understand what those lines does ;-) Remember: A script can only do, what you can do in the interface.

                                   

                                  In the interface you would fill in findTo and changeTo. After that, you would click on the button change(). Nothing else with scripting.

                                  So if you insert mTarget.changeGrep();  multiple times, you will get your desired result. Of course, this can be written shortener with a for-loop.

                                  • 14. Re: How can find-change grep only on Masters
                                    Teetan VK Level 1

                                    thank you jarek,

                                    and sorry

                                     

                                    thank you all guys

                                     

                                    I will repeat the script again and again

                                     

                                    Teetan

                                    • 15. Re: Re: How can find-change grep only on Masters
                                      Kai Rübsamen Adobe Community Professional

                                      Repeating a script multiple times is surely not a good solution. I would do it in the following way.

                                       

                                      Try to understand what is going on here and see the differences between these lines and the last script!

                                       

                                      if ( app.documents.length > 0 ) { 
                                          if ( app.scriptPreferences.version >= 6 ) {
                                              app.doScript( main, ScriptLanguage.JAVASCRIPT , [], UndoModes.ENTIRE_SCRIPT, "Search in masterpages" );         
                                          } 
                                          else {
                                              main();
                                          }
                                      } else {
                                          alert ( "No documents open!" );
                                      }
                                      
                                      function main() {
                                      
                                          // Your settings
                                          // ---
                                          var searchList = [
                                              [ "USA" , "Obama" ],
                                              [ "rocket" , "sky" ],
                                              [ "New York" , "Los Angeles" ]
                                          ];
                                      
                                          app.findGrepPreferences = app.changeGrepPreferences = null;
                                          app.findChangeGrepOptions.includeMasterPages = true;
                                          var target = app.documents.everyItem().masterSpreads.everyItem().textFrames.everyItem();
                                          
                                          for ( var j = 0; j < searchList.length; j++ ) {
                                              var curSearch = searchList[j];
                                              app.findGrepPreferences.findWhat = curSearch[0];  
                                              app.changeGrepPreferences.changeTo= curSearch[1];  
                                              target.changeGrep();  
                                          }     
                                          app.findGrepPreferences = app.changeGrepPreferences = null; 
                                      } // main
                                      

                                       

                                       

                                      – Kai

                                      • 16. Re: How can find-change grep only on Masters
                                        Jump_Over Level 5

                                        Hi,

                                         

                                        As Kai said, to understand a code is a basic step you should do.

                                        I would modify Kai's code in case of mTarget declaration point ==> I mean I would redeclare it inside each for...loop's run (at the end of loop).

                                        Just in case we are working with changing contents here.

                                         

                                        Jarek

                                        • 17. Re: How can find-change grep only on Masters
                                          Teetan VK Level 1

                                          Hi

                                           

                                          and thank you all guys, for your help

                                           

                                          appreciate

                                           

                                          Teetan