• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

TextItem.size is wrong after transform (CS 6)

Community Beginner ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

4.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Valorous Hero ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

Have a look at this thread...

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 26, 2013 Feb 26, 2013

Copy link to clipboard

Copied

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[1].toString()],[getTextSize(Number(txtLayers[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);
}


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2013 Feb 27, 2013

Copy link to clipboard

Copied

Thanks a lot, works great!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 28, 2013 Jun 28, 2013

Copy link to clipboard

Copied

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!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 02, 2013 Jul 02, 2013

Copy link to clipboard

Copied

Hi,

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

Regards,

Vinoth

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 11, 2013 Dec 11, 2013

Copy link to clipboard

Copied

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)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2013 Dec 12, 2013

Copy link to clipboard

Copied

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. 

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

LATEST

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'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines