8 Replies Latest reply on Jun 18, 2011 9:43 AM by c.pfaffenbichler

    Need help subscripting in a text layer

    Jason35620

      Hi.  I need some help getting the Java Script right for subscripting in a text layer.

       

      Specifically, I need to access the text in layers named "Formula1" "Formula2" thru "Formula6", find each number in the text and subscript it.

       

      I actually want to set the baseline for that character to -3

       

      I usually write code in VBA, and JavaScript is winning the battle!  I need Java so I can share it with someone on a mac. 

       

      Ideas?  Help?  I'll take em!  Thanks!

        • 1. Re: Need help subscripting in a text layer
          c.pfaffenbichler Level 9

          I have not been able to solve the issue yet, but maybe the code xbytor provides in this thread may get you started.

           

          http://www.ps-scripts.com/bb/viewtopic.php?f=9&t=2819&p=12293&hilit=baseline+shift&sid=f1f 26195d8b46af4bcf7ef1823d72253#p12293

          1 person found this helpful
          • 2. Re: Need help subscripting in a text layer
            Jason35620 Level 1

            Thanks for searching.  JS is wearing me out! :O)

             

            I think I'll try AppleScript until I have many hours to devote to this effort.

             

            Thanks again...

            • 3. Re: Need help subscripting in a text layer
              Muppet Mark Level 5

              I don't think the change in scripting language is going to help you here… Access to text in Photoshop is very limited. If anything can be done then it's going to be in X's stuff, complicated at best, my guess is with lots of action manager code. The only way you can utilize this from AppleScript is to call 'do Javascript' which is just going to put you back to square one…

              • 4. Re: Need help subscripting in a text layer
                c.pfaffenbichler Level 9

                I have not been able so far to make the ActionDescriptor-code work for the task reliably.

                It should work, but as far as I can tell one may have to assess dozens and dozens of type-specific settings (from font to color to warp and so on and so forth) if one wants to avoid inadvertently changing those features for either or both the letters that are supposed to have a baseline shift applied as the rest of the text in the Layer.

                • 5. Re: Need help subscripting in a text layer
                  Michael L Hale Level 5

                  As others have said, to change the format of just some of the chars in a textItem can only be done with Action Manager. On Windows you can use javascript or VB. On Mac you can only use javascript.

                   

                  A textItem's descriptor has 10 keys. The one controls that kind of char formatting is stored in the 'textStyleRange' key. That one descriptor has 69 keys that store the formatting for that range. There may be several ranges.. Some of the keys in 'textStyleRange'  are also descriptors that have their own keys. To avoid unwanted changes to the existing formatting you need to read all those keys, change only the 'baselineShift' key in the 'textStyleRange' descriptor, then write all the settings back to the textItem's descriptor.

                   

                  It may be that it is possible to do this kind of format editing with a script but it would take a lot of work and many, many line of code. It also would take a good understanding of how Action Manager works with it's actionDescriptors, actionReferences, actionLists, and their methods and properties.

                   

                  It has been a good while since I looked at Xbytor's script, but when I last looked it only supports limited formatting and overwrites existing formatting it doesn't support with default text formatting. If your text doesn't have any special formatting his script would be the best way to go.

                   

                  If your text does have formatting unsported by X's script you will either need to expand his script or create your own. Unless this kind of text editing is something that you need to do very often it may not be worth the effort.

                  • 6. Re: Need help subscripting in a text layer
                    c.pfaffenbichler Level 9

                    Thanks, Mike!

                    I hadn’t figured out the total number of keys yet (Edit: and I doubt I would ever have …), but what you tell about it is fairly discouraging.

                    • 7. Re: Need help subscripting in a text layer
                      Michael L Hale Level 5

                      To add to the discouragement, CS5 has more 'textStyle' keys than CS4. There may be other changes with other versions. So you will need to check if the key exists before you try to read it. And at least on my system a typo in the code can crash Photoshop.

                       

                      Here is one way to get the keys.

                      var ref = new ActionReference();
                      ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                      var layerDesc = executeActionGet(ref);
                      var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
                      var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
                      // there will be at least one range so just get the first range descriptor
                      var styleDesc = rangeList.getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle'));
                      
                      var c = styleDesc.count;
                      var str = '';
                      for(var i=0;i<c;i++){ //enumerate descriptor's keys
                             str = str + 'Key '+i+' = '+typeIDToStringID(styleDesc.getKey(i))+': '+styleDesc.getType(styleDesc.getKey(i))+'\n';
                      }
                      alert(str);
                      
                      • 8. Re: Need help subscripting in a text layer
                        c.pfaffenbichler Level 9

                        Thanks again, Michael!