4 Replies Latest reply on Apr 12, 2018 3:31 PM by r-bin

    Read and change specific words in a text layer

    Gustavo Del Vechio Level 3



      I have a text layer in Adobe Photoshop (it's a text-frame). Suppose I deffined it as a variable called "myText"... by using:


      var myText = app.activeDocument.layers.getByName("dados"); 


      In Adobe Illustrator, I can simply use the property: "words" in order to acess an array of all words in the text frame. I could declare anything like:


      var countWords = myText.words;


      And...after... I can acess the "countWords[1]", "countWords[2]".... to acess all individual words and personalize them.


      Looking at Photoshop documentation I did not find similar property or object or instance... In "textItem" object there's no "paragraph" or "words" option that I can try.


      Is there any way in Photoshop I can acess individual words in a text frame layer, so I could, for example, chance the color of this word...or increase the size of just this word?


      Thank you very much for the help.



        • 1. Re: Read and change specific words in a text layer
          pixxxel schubser MVP & Adobe Community Professional

          Hi Gustavo,

          some snippets and or possible ways could be find here: Changing color of text found with regex

          1 person found this helpful
          • 2. Re: Read and change specific words in a text layer
            r-bin Level 4

            You can change the text parameters for a specific

            position and length using this function. The words and their positions in the text will have to be searched for.


            var c1 = new SolidColor();
            with (c1.rgb) { red   = 200; green = 100; blue = 150; } 
            var c2 = new SolidColor();
            with (c2.rgb) { red   = 20; green = 100; blue = 200; } 
            // activeLayer in demo example must be textlayer
            activeDocument.activeLayer.textItem.size = 12;
            activeDocument.activeLayer.textItem.contents = "0123456789012345678901234567890";
            // examples
            set_text_style(0, 4, 50)
            set_text_style(4, 4, 70, c1)
            set_text_style(10, 5, 30, c2)
            function set_text_style(from, len, size, color)
                try {
                    var d = new ActionDescriptor();
                    var r = new ActionReference();
                    r.putEnumerated(stringIDToTypeID("textLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
                    d.putReference(stringIDToTypeID("null"), r);
                    var d1 = new ActionDescriptor();
                    var list1 = new ActionList();
                    var d2 = new ActionDescriptor();
                    d2.putInteger(stringIDToTypeID("from"), from);
                    d2.putInteger(stringIDToTypeID("to"), from+len);
                    var d3 = new ActionDescriptor();
                    d3.putUnitDouble(stringIDToTypeID("size"), stringIDToTypeID("pointsUnit"), size);
                    if (color != undefined)
                        var d4 = new ActionDescriptor();
                        d4.putDouble(stringIDToTypeID("red"),   color.rgb.red);
                        d4.putDouble(stringIDToTypeID("green"), color.rgb.green);
                        d4.putDouble(stringIDToTypeID("blue"),  color.rgb.blue);
                        d3.putObject(stringIDToTypeID("color"), stringIDToTypeID("RGBColor"), d4);
                    d2.putObject(stringIDToTypeID("textStyle"), stringIDToTypeID("textStyle"), d3);
                    list1.putObject(stringIDToTypeID("textStyleRange"), d2);
                    d1.putList(stringIDToTypeID("textStyleRange"), list1);
                    d.putObject(stringIDToTypeID("to"), stringIDToTypeID("textLayer"), d1);
                    executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
                catch (e) { throw(e); } 
            2 people found this helpful
            • 3. Re: Read and change specific words in a text layer
              Gustavo Del Vechio Level 3

              Thank you very much pixxxel and r-bin.


              It's clear it's not so easy to process, but it's possible to try these codes!


              If I find it still difficult to work, perhaps I will pass the code to Illustrator process (script to Illustrator) and use BridgeTalk to process the necessary photos in Photoshop!


              Thank you very much



              • 4. Re: Read and change specific words in a text layer
                r-bin Level 4

                You can add other parameters. Which ones can be found with the help of the ScriptListener plugin.


                For example


                d3.putBoolean(stringIDToTypeID("styleSheetHasParent"), true);
                d3.putString(stringIDToTypeID("fontPostScriptName"), "ArialMT");
                d3.putString(stringIDToTypeID("fontName"), "Arial");
                d3.putString(stringIDToTypeID("fontStyleName"), "Regular");
                d3.putInteger(stringIDToTypeID("fontScript"), 0);
                d3.putInteger(stringIDToTypeID("fontTechnology"), 1);
                d3.putDouble(stringIDToTypeID("horizontalScale"), 69.1);
                d3.putDouble(stringIDToTypeID("verticalScale"), 89,1);
                d3.putBoolean(stringIDToTypeID("syntheticBold"), true);
                d3.putBoolean(stringIDToTypeID("syntheticItalic"), true);
                d3.putBoolean(stringIDToTypeID("autoLeading"), false);
                d3.putUnitDouble(stringIDToTypeID("leading"), stringIDToTypeID("pointsUnit"), 8);
                d3.putInteger(stringIDToTypeID("tracking"), -10);
                d3.putUnitDouble(stringIDToTypeID("baselineShift"), stringIDToTypeID("pointsUnit"), 20);
                d3.putEnumerated(stringIDToTypeID("autoKern"), stringIDToTypeID("autoKern"), stringIDToTypeID("opticalKern"));
                d3.putEnumerated(stringIDToTypeID("fontCaps"), stringIDToTypeID("fontCaps"), stringIDToTypeID("smallCaps"));
                d3.putEnumerated(stringIDToTypeID("digitSet"), stringIDToTypeID("digitSet"), stringIDToTypeID("defaultDigits"));
                d3.putEnumerated(stringIDToTypeID("baseline"), stringIDToTypeID("baseline"), stringIDToTypeID("subScript"));
                d3.putEnumerated(stringIDToTypeID("strikethrough"), stringIDToTypeID("strikethrough"), stringIDToTypeID("xHeightStrikethroughOn"));
                d3.putEnumerated(stringIDToTypeID("underline"), stringIDToTypeID("underline"), stringIDToTypeID("underlineOnLeftInVertical"));
                d3.putBoolean(stringIDToTypeID("altligature"), true);
                d3.putEnumerated(stringIDToTypeID("textLanguage"), stringIDToTypeID("textLanguage"), stringIDToTypeID("englishLanguage"));