3 Replies Latest reply on Aug 9, 2014 1:13 PM by Dobygm

    How can I make a long list find-change only on Master

    Teetan VK Level 1

      Hi everyone

       

      I got this script:

       

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

      var myDocuments = app.documents.everyItem();
      var myLayers = myDocuments.layers.everyItem();

      //Locked text frames on master spreads are not touched.
      //If you want to unlock them you have to add something like this:

      //Unlock ALL page items in every document on spreads and master spreads (optional):
      myDocuments.pageItems.everyItem().locked = false;

      var myPageItemsOnNormalSpreads = myDocuments.spreads.everyItem().pageItems.everyItem();

      //Unlock the layers (optional)
      myLayers.locked = false;

      //Lock all first level page items on normal spreads
      //That leaves the page items on master spreads unlocked:
      myPageItemsOnNormalSpreads.locked = true;

      //Now for the GREP part:
      app.findChangeGrepOptions.includeMasterPages = true;
      app.findGrepPreferences = changeGrepPreferences = null;
      app.findGrepPreferences.findWhat = "\\b20\\d+\\b";

      //Do the search on "all open document" level
      //That will return an array of arrays:
      var myTarget = myDocuments.findGrep();

      //Flattening the myTarget array:
      var flattenedFoundArray = [];

      for(var n=0;n<myTarget.length;n++){
          flattenedFoundArray = flattenedFoundArray.concat(myTarget[n]);
          };

      //Change contents of found texts in flattened array:
      for(var n=flattenedFoundArray.length-1;n>=0;n--){
          flattenedFoundArray[n].contents = String(Number(flattenedFoundArray[n].contents) + 1);
          };

      //Unlock all objects on normal spreads:
      myPageItemsOnNormalSpreads.locked = false;

      //Reset GREP find and change prefs:
      app.findGrepPreferences = changeGrepPreferences = null;

       

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

       

      made by Uwe

       

      I change it into this, aim to make a mulit items of find-change only on master

       

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

       

      var myDocuments = app.documents.everyItem();
      var myLayers = myDocuments.layers.everyItem();

      //Locked text frames on master spreads are not touched.
      //If you want to unlock them you have to add something like this:

      //Unlock ALL page items in every document on spreads and master spreads (optional):
      myDocuments.pageItems.everyItem().locked = false;

      var myPageItemsOnNormalSpreads = myDocuments.spreads.everyItem().pageItems.everyItem();

      //Unlock the layers (optional)
      myLayers.locked = false;

      //Lock all first level page items on normal spreads
      //That leaves the page items on master spreads unlocked:
      myPageItemsOnNormalSpreads.locked = true;

      //Now for the GREP part:
      app.findChangeGrepOptions.includeMasterPages = true;
      app.findGrepPreferences = changeGrepPreferences = null;
      app.findGrepPreferences.findWhat = "USA";

      //Do the search on "all open document" level
      //That will return an array of arrays:
      var myTarget = myDocuments.findGrep();

      //Flattening the myTarget array:
      var flattenedFoundArray = [];

      for(var n=0;n<myTarget.length;n++){
          flattenedFoundArray = flattenedFoundArray.concat(myTarget[n]);
          };

      //Change contents of found texts in flattened array:
      for(var n=flattenedFoundArray.length-1;n>=0;n--){
          flattenedFoundArray[n].contents = "CHINA";
          };

      //Unlock all objects on normal spreads:
      myPageItemsOnNormalSpreads.locked = false;

      //Reset GREP find and change prefs:
      app.findGrepPreferences = changeGrepPreferences = null;


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

      var myDocuments = app.documents.everyItem();
      var myLayers = myDocuments.layers.everyItem();

      //Locked text frames on master spreads are not touched.
      //If you want to unlock them you have to add something like this:

      //Unlock ALL page items in every document on spreads and master spreads (optional):
      myDocuments.pageItems.everyItem().locked = false;

      var myPageItemsOnNormalSpreads = myDocuments.spreads.everyItem().pageItems.everyItem();

      //Unlock the layers (optional)
      myLayers.locked = false;

      //Lock all first level page items on normal spreads
      //That leaves the page items on master spreads unlocked:
      myPageItemsOnNormalSpreads.locked = true;

      //Now for the GREP part:
      app.findChangeGrepOptions.includeMasterPages = true;
      app.findGrepPreferences = changeGrepPreferences = null;
      app.findGrepPreferences.findWhat = "Washington DC";

      //Do the search on "all open document" level
      //That will return an array of arrays:
      var myTarget = myDocuments.findGrep();

      //Flattening the myTarget array:
      var flattenedFoundArray = [];

      for(var n=0;n<myTarget.length;n++){
          flattenedFoundArray = flattenedFoundArray.concat(myTarget[n]);
          };

      //Change contents of found texts in flattened array:
      for(var n=flattenedFoundArray.length-1;n>=0;n--){
          flattenedFoundArray[n].contents = "Beijing";
          };

      //Unlock all objects on normal spreads:
      myPageItemsOnNormalSpreads.locked = false;

      //Reset GREP find and change prefs:
      app.findGrepPreferences = changeGrepPreferences = null;


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

       

      only what I can do is repeat and repeat again

       

      is that another perfect solution to do that?

       

      thanks

       

      Teetan

        • 1. Re: How can I make a long list find-change only on Master
          Sajeev Sridharan Level 4

          Try this,

           

          findChange("USA", "CHINA");
          findChange("Washington DC", "Beijing");
          
          
          function findChange (findWhat, changeContent){
              var myDocuments = app.documents.everyItem();
              var myLayers = myDocuments.layers.everyItem();
              //Locked text frames on master spreads are not touched.
              //If you want to unlock them you have to add something like this:
              //Unlock ALL page items in every document on spreads and master spreads (optional):
              myDocuments.pageItems.everyItem().locked = false;
              var myPageItemsOnNormalSpreads = myDocuments.spreads.everyItem().pageItems.everyItem();
              //Unlock the layers (optional)
              myLayers.locked = false;
              //Lock all first level page items on normal spreads
              //That leaves the page items on master spreads unlocked:
              myPageItemsOnNormalSpreads.locked = true;
              //Now for the GREP part:
              app.findChangeGrepOptions.includeMasterPages = true;
              app.findGrepPreferences = changeGrepPreferences = null;
              if(findWhat)app.findGrepPreferences.findWhat = findWhat;
              //Do the search on "all open document" level
              //That will return an array of arrays:
              var myTarget = myDocuments.findGrep();
              //Flattening the myTarget array:
              var flattenedFoundArray = [];
              for(var n=0;n<myTarget.length;n++){
                  flattenedFoundArray = flattenedFoundArray.concat(myTarget[n]);
                  };
              //Change contents of found texts in flattened array:
              for(var n=flattenedFoundArray.length-1;n>=0;n--){
                  if(changeContent)flattenedFoundArray[n].contents = changeContent;
                  };
              //Unlock all objects on normal spreads:
              myPageItemsOnNormalSpreads.locked = false;
              //Reset GREP find and change prefs:
              app.findGrepPreferences = changeGrepPreferences = null;
          }
          

           

           

          Vandy

          • 2. Re: How can I make a long list find-change only on Master
            Teetan VK Level 1

            Perfect!

             

            Thank you Vandy, thank you so much!

             

            Teetan

            • 3. Re: How can I make a long list find-change only on Master
              Dobygm

              Hi,

              this is perfect,

              I am new to coding. How could this be applied only to the active story. To simplify script code?

              Thank you very much.