2 Replies Latest reply on Aug 18, 2010 10:13 AM by norway_photo

    Change text using VBS

    ineteye2

      How can i change text using VBScript in PSD file?

      (for Example from "TEST" to "HELLO WORLD" .)

        • 1. Re: Change text using VBS
          Muppet Mark-QAl63s Level 4

          This is NOT VB but should either give you a pointer as to what you need to do in VB or you could call this string using the app's 'do javascript' command… You deal with the layer's text item but you need to test that the layer in question as a valid text layer before else you will get an error…

           

          Im almost certain that the scripting guides include a sample of doing this in each of the scripting languages… So take a look at those too…

           

          var docRef = app.activeDocument;
          if (docRef.activeLayer.kind == LayerKind.TEXT) docRef.activeLayer.textItem.contents = "HELLO WORLD";
          

          • 2. Re: Change text using VBS
            norway_photo

            Here is a code i use to change 3 text layers in a open file. the text layers are labeled "name", "year" and "number"

            And it takes the info from the images filname "year_name_number_originalfilename.xxx"

             

            It should help you get your work done:

             

            var docRef = activeDocument;

            // strip the extension off


            var fileNameNoExtension = docRef.name;
            fileNameNoExtension = fileNameNoExtension.split( "_" );
            if ( fileNameNoExtension.length > 1 ) {
                            fileNameNoExtension.length--;
            }

            fileNameNoExtension = fileNameNoExtension.join("_");

            var myString = fileNameNoExtension;
            var mySplitResult = myString.split("_");

             

            var textLayer = docReflayers['Year']; // define the existing text layer to a var
            docRef.activeLayer = textLayer;
            textLayer.kind = LayerKind.TEXT;
            var T1 = textLayer.textItem;
            T1.contents = mySplitResult[0]

            var textLayer = docRef.layers['Name']; // define the existing text layer to a var
            docRef.activeLayer = textLayer;
            textLayer.kind = LayerKind.TEXT;
            var T2 = textLayer.textItem;
            T2.contents = mySplitResult[1]

             

            var textLayer = docRef.layers['Number']; // define the existing text layer to a var
            docRef.activeLayer = textLayer;
            textLayer.kind = LayerKind.TEXT;
            var T3 = textLayer.textItem;
            T3.contents = mySplitResult[2]

             

            Hope it helped!

             

            Eivind