13 Replies Latest reply on Dec 13, 2013 12:28 PM by Michael L Hale

    TextItem.size is wrong after transform (CS 6)

    AlexAdam82

      Hey, i've a export script for Photoshop, which creates a XML file.

      On field in this XML is the font size for each text layer. But the .size value is wrong when we transform the text layer.

      Example and steps to reproduce:

       

      1. create a text layer
      2. set font size 6pt (font family doesn't matter)
      3. TextItem.size will export "6 pt"
      4. transform the text - make it larger
      5. Photoshop shows for example "12 pt" as the font size
      6. TextItem.size still exports "6 pt"

       

      Is there any way to get the correct font size?

       

      When transforming text, you will get a value like "11.9999 pt" (you mostly don't get a round number).

      But when you try to set the font size to 12 pt manually, TextItem.size still exports the old value.

       

      The exporter works great in CS 3, the font sizes are correct. But in CS 6 its wrong.

      Is this a PS bug maybe?

       

      Alex

        • 1. Re: TextItem.size is wrong after transform (CS 6)
          Paul Riggott Level 6

          Have a look at this thread...

          http://forums.adobe.com/message/4902706

          1 person found this helpful
          • 2. Re: TextItem.size is wrong after transform (CS 6)
            AlexAdam82 Level 1

            Hey Paul, thanks for that. Is it also possible to use it for multiple layers?

            And does it work also for saved and reopend PSD files?

             

            Alex

            • 3. Re: TextItem.size is wrong after transform (CS 6)
              Paul Riggott Level 6

              At the moment it returns the value for tha active layer, it could be modified so that it returns the value via the layers Index or ID.

              Yes it will work on a re-opened psd.

              • 4. Re: TextItem.size is wrong after transform (CS 6)
                Paul Riggott Level 6

                Here is an example of getting all text layer names and font sizes...

                 

                 

                main();
                function main(){
                if(!documents.length) return;
                var txtLayers = getNamesPlusIDs();
                var txtSize = new Array();
                for(var a in txtLayers){
                    txtSize.push([[txtLayers[a][1].toString()],[getTextSize(Number(txtLayers[a][0]))]]);
                    }
                alert(txtSize.join('\n'));
                }
                function getNamesPlusIDs(){ 
                   var ref = new ActionReference(); 
                   ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
                   var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1; 
                   var Names=[];
                try{
                    activeDocument.backgroundLayer;
                var i = 0; }catch(e){ var i = 1; };
                   for(i;i<count;i++){ 
                       if(i == 0) continue;
                        ref = new ActionReference(); 
                        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
                        var desc = executeActionGet(ref);
                        var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));
                        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
                        if(layerName.match(/^<\/Layer group/) ) continue;
                        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
                        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
                        if(desc.hasKey(stringIDToTypeID('textKey'))) Names.push([[Id],[layerName]]);
                   }; 
                return Names;
                };
                function getTextSize(ID){
                var ref = new ActionReference();
                ref.putIdentifier(charIDToTypeID('Lyr '), ID);
                var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'));
                var textSize =  desc.getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle')).getDouble (stringIDToTypeID('size'));
                if (desc.hasKey(stringIDToTypeID('transform'))) {
                            var mFactor = desc.getObjectValue(stringIDToTypeID('transform')).getUnitDoubleValue (stringIDToTypeID("yy") );
                    textSize = (textSize* mFactor).toFixed(2);
                    }
                return Number(textSize).toFixed(2);
                }
                
                
                 
                
                1 person found this helpful
                • 5. Re: TextItem.size is wrong after transform (CS 6)
                  AlexAdam82 Level 1

                  Thanks a lot, works great!

                  • 6. Re: TextItem.size is wrong after transform (CS 6)
                    vinoth_mannu Level 1

                    Hi,

                     

                    Further amendements requried

                     

                    I have added the scripts in my event manager "save document".

                     

                    Some of the files are saved without textitem, but still i am getting alert message. I need alert only for the textitem.

                     

                    Any help!!!

                    • 7. Re: TextItem.size is wrong after transform (CS 6)
                      vinoth_mannu Level 1

                      Hi,

                       

                      This is urgent, Could any one suggest me to right path to achive my requirement.

                       

                      Regards,

                      Vinoth

                      • 8. Re: TextItem.size is wrong after transform (CS 6)
                        mightysprite Level 1

                        Is there really no way to access the transform via the "normal" scripting interface of objects etc? I'm new to this Photoshop scripting stuff but the above code looks a lot more like that which is spit out of the listener plugin for compiled code than Javascript. Notable of course is that you're hardcoding strings in there rather than using the convenience macros from PITerminology.h. Is there a writeup anywhere that discusses the differences between the C and JSX interfaces (or maybe just the sorts of things that aren't "native" via JSX)?

                        • 9. Re: TextItem.size is wrong after transform (CS 6)
                          JJMack Most Valuable Participant

                          There is no Adobe DOM method for transform. The closest method DOM has to offer is resize,

                           

                          resize([horizontal][, vertical][, anchor])

                          number number AnchorPosition

                          Resizes the layer to the specified dimensions (as a percentage of its current size) and places it in the specified position.

                           

                          I normally save, set Photoshop preference interpolation method resize then restore Photoshop preference.  This is a problem in CS6 if the user left Adobe new default Bicubic Automatic as their setting.  Adobe failed to add support for that in its scripting support. Is fixed in CC.

                           

                          So if all you want to do is scale you have resize. 

                          • 10. Re: TextItem.size is wrong after transform (CS 6)
                            Michael L Hale Level 5

                            mightysprite wrote:

                             

                            Is there really no way to access the transform via the "normal" scripting interface of objects etc?

                            The short answer is no, you can not access the text transform value using the DOM. The snarky answer is actionDescriptor, actionReference, etc are DOM objects and executeAction is a DOM method so you can.

                            • 11. Re: TextItem.size is wrong after transform (CS 6)
                              mightysprite Level 1

                              I normally save, set Photoshop preference interpolation method resize then restore Photoshop preference.  This is a problem in CS6 if the user left Adobe new default Bicubic Automatic as their setting.  Adobe failed to add support for that in its scripting support. Is fixed in CC.

                               

                              So if all you want to do is scale you have resize. 

                               

                              Ok, thanks. The behavior that I'm seeing, which led me here, is that setting the textItem.contents resizes the item to the value that is in the textItem.size property, which does not match what shows up in the UI. So I need to compute what the apparent object size using functionality like above and then reset it correctly after I change the textItem's contents. (This behavior is 100% reproducable for me but I don't have minimal instructions yet on how to create a scene that demonstrates it.)

                               

                              In other words, I'm not looking to scale or resize per se, I'm looking to restore the item's size after it mysteriously changes.

                               

                              In case the above sounded weird, here's what I see in my demo file.

                               

                              textItem.contents is "12345"

                              textItem.size reports 82.something

                              text tool UI reports 216 pt.

                               

                              in ESTK ...textItem.contents = "foo"

                               

                              textItem.contents is now "foo"

                              textItem.size reports 32.something

                              text tool UI reports 82.something pt.

                               

                              in ESTK ...textItem.contents = "bar"

                               

                              textItem.contents is now "bar"

                              textItem.size reports something smaller, 12 or so

                              text tool UI reports 32.something pt.

                              • 12. Re: TextItem.size is wrong after transform (CS 6)
                                mightysprite Level 1

                                Michael L Hale wrote:

                                 

                                The short answer is no, you can not access the text transform value using the DOM. The snarky answer is actionDescriptor, actionReference, etc are DOM objects and executeAction is a DOM method so you can.

                                 

                                Ok, fair enough. Is the documentation on what's available to do pretty much exclusively here and on ps-scripts, or is there actual documentation somewhere that I somehow haven't found on what actions are available and what properties they take? I modified the above script to take a layer by name and just sort of had to guess at what to put in (I'd assumed that I wanted to use 'LyrN' instead of 'Lyr ' but was wrong, for example); I'd like to get deeper into scripting Photoshop in clever ways but it seems a lot like trial and error (especially since the error you get is something to the effect of, "something went wrong or maybe this version of Photoshop doesn't support what you were trying to do"). Thankfully the iteration loop isn't too long but it sure would be nice to be able to use var declarations in the console. 

                                 

                                Edit: oh sorry, it wasn't the above script that I edited but it was one similar that showed how to get the actual text size from the reported size * transform.yy.

                                • 13. Re: TextItem.size is wrong after transform (CS 6)
                                  Michael L Hale Level 5

                                  I agree that the official documentation on using Action Manager in javascript is poor to non-existent so your best source is the user forums. I think PS-Scripts is better but I'll admit to being biased about that.

                                   

                                  If you wanted to reference a layer by name and the code you have references by index and you have a line that reads

                                  ref.putIndex( charIDToTypeID( 'Lyr ' ), i );// class,index property
                                  

                                  If you look in the javascript reference under ActionReference you see that putIndex has two arguments. The first is the class and the second it the index as a number. The charID 'LyrN' does map to the stringID 'layerName'. But name is a property so would be used where a class ID is required. Instead you  change the method to putName and it will use the name instead of the index.

                                  ref.putName( charIDToTypeID( 'Lyr ' ), layerNamei );// class,name properry
                                  

                                   

                                  Making a guess about which ID to use is never a good idea but I will admit that I have done that more than once.

                                   

                                  It is also true that the error messages are long longer very helpful. At one time Photoshop did have much better error messages for what caused the error. Not they might as well just say 'Error'.