3 Replies Latest reply on May 20, 2014 12:38 AM by Laubender

    Find and change all layers

    AsOne

      Hi All,

       

      How can I find and change in all layers if layer hidden

       

      app.findGrepPreferences.findWhat = "\\s\\s+  ";

      app.changeGrepPreferences.changeTo = " ";

      app.changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;

       

       

      Thanks

      Steve

        • 1. Re: Find and change all layers
          Harbs. Level 6
          app.findChangeGrepOptions.includeHiddenLayers = true;
          
          • 2. Re: Find and change all layers
            Laubender Adobe Community Professional & MVP

            @Steve – check the variable visible for all layers in the document, store some information about that layers, set visibility of all layers to true, search, replace, set back the original visibility of all layers.

             

            Like that with storing the unique ID for invisible layers in an array:

             

            //Temporarily make all non-visible layers visible
            //Search and replace
            //Set the visibility of all layers back again
            
            //If you want to access locked layers as well, expand this example.
            
            //1. Store all IDs of all hidden layers in array:
            var myDoc = app.documents[0];
            var allHiddenLayersID = new Array();
            var allLayers = myDoc.layers;
            
            for(var n=0;n<allLayers.length;n++){
                if(!allLayers[n].visible){allHiddenLayersID.push(allLayers[n].id)};
                };
            
            //2. Set all layers of document to visible:
            myDoc.layers.everyItem().visible = true;
            
            //3. Do your search/replace
            
            app.findGrepPreferences.findWhat = "\\s\\s+  ";
            app.changeGrepPreferences.changeTo = " ";
            
            app.changeGrep();
            
            app.findGrepPreferences = app.changeGrepPreferences = null;
            
            //4. Change all formerly hidden layers back to visible = false:
            for(var n=0;n<allHiddenLayersID.length;n++){
                myDoc.layers.itemByID(allHiddenLayersID[n]).visible = false;
                };
            

             

            Locked layers will not be searched.

            If you want that, you could expand this example with a second array for locked is true.

             

            Uwe

            • 3. Re: Find and change all layers
              Laubender Adobe Community Professional & MVP

              Yeah. Harbs is right. There is an easy control in the findChangeGrepOptions. Much faster.

              Of course after the search/replace set it back to its original value.

               

              For locked layers change my example to the variable locked instead of visible.

               

              Uwe