5 Replies Latest reply on Dec 7, 2011 1:18 PM by Clevadio

    Find & replace

    Clevadio Level 1

      I am having difficultiy finding a way to change specific text lines within a document in a batch situation. Typically if I do with an action the font size changes or there is a number of situations.  I am hoping someone might be able to point me in the right direction.

        • 1. Re: Find & replace
          c.pfaffenbichler Level 9

          The textItem’s contents might be what you are after.

          But why not elaborate a bit, maybe with a few screenshots, so we can help you?

          • 2. Re: Find & replace
            Ghoulfool Level 1

            You could try my seek and destroy script. Don't wory about the name, it doesn't actually destroy anything and was originally called Search and Replace but so far to my knowledge that's not a Metallica song.

            Anyhoo copy the script save it out as a .jsx file

            It'll prompt you for the text to seach for and the text to replace it with then it'll go through all the layers and change them accordingly. It should do what you want.

            So far it works ok but has a problem with with Layer groups - but I'm just working on that.

             

            // ******************************************************
            //
            // Seek and Destroy
            // written by GhoulFool
            // Date: 4th April 2011
            // version .5
            // Description:
            // searches for text in layer names and replaces it
            // ******************************************************

             

            var srcDoc = app.activeDocument;
            fileName = app.activeDocument.name;
            var search = new Object();
            var replace = new Object();
            search.pattern = prompt('Enter the search pattern to look for for all layers.\n', 'Search');
            replace.pattern = prompt('Enter the word to REPLACE ' + search.pattern + '.\n', 'Replace');
            alert("Replacing  '"+ search.pattern + "' to be replaced with '" + replace.pattern + "'.")
            var mySearch = search.pattern;
            var myReplace = replace.pattern;
            var numLayers = srcDoc.layers.length;
            var layers = srcDoc.layers;     
            processLayers (srcDoc)
            function processLayers (srcDoc)
            {
               for (var i = 0; i < numLayers; i++)
                  {
                     var layer = layers[i];
                     if (layer.typename == 'LayerSet')
                     {
                        alert("This is a group")
                     }
                   
                  else
                
                     {
                  var thisLayer = srcDoc.artLayers[i].name.toLowerCase();

             

                        tempName = app.activeDocument.artLayers[0].name.toLowerCase();

             

                     if (thisLayer.search(mySearch) != -1)
                      
                        {
                        tempName = app.activeDocument.artLayers[i].name.toLowerCase();
                        app.activeDocument.artLayers[i].name = tempName.replace(mySearch,myReplace)
                        }
                     }
                  }

             

            } // function close

            • 3. Re: Find & replace
              Muppet Mark-QAl63s Level 4

              Ghoulfool, your script is for the names of the layers… BTW I made one that works thru all sub layers with a couple of options only yesterday its at home thou. I think the OP wants to actually deal with the content of text layers… I'll post my script later when I get home if you want it…? I only need to add a little UI to it.

              • 4. Re: Find & replace
                Ghoulfool Level 1

                Remember kids: Drink coffee first THEN reply to posts. Never the other way around it can lead to confusion.

                • 5. Re: Find & replace
                  Clevadio Level 1

                  Thanks to everyone that assisted, I eventually worked it out. I actually forgot about this post but didn't want to leave yall hanging. Muppet Mark, you were right. Thanks again