0 Replies Latest reply on Aug 3, 2014 5:45 AM by Teetan VK

    Why this script unfunction?

    Teetan VK Level 1

      Hi everyone

       

      I try joint to scripts togeter:

       

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

       

      function main() {
          // Your settings
          // ---
        
      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;

          var searchList = [
              [ "USA" , "Obama" ],
              [ "rocket" , "sky" ],
              [ "New York" , "Los Angeles" ]
          ];

          app.findChangeGrepOptions.includeMasterPages = true;
          app.findGrepPreferences = app.changeGrepPreferences = null;

      var myTarget = myDocuments.findGrep();

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

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

      for(var n=flattenedFoundArray.length-1;n>=0;n--){
          flattenedFoundArray[n].contents = searchList;

          for ( var j = 0; j < searchList.length; j++ ) {
              var curSearch = searchList[j];
              app.findGrepPreferences.findWhat = curSearch[0];
              app.changeGrepPreferences.changeTo= curSearch[1];
              target.changeGrep();
          }   
          };

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

          app.findGrepPreferences = app.changeGrepPreferences = null;

      } // main

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

      the orginal script:

       

      How can I combine two very good ideas together?

       

      but unfunction

      can you fix it?

       

       

      thanks

       

      Teetan