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

Layer scale factor

New Here ,
Sep 19, 2014 Sep 19, 2014

Let's say I create a text layer with 50pt font size, then I transform the layer to make it bigger. Is there a variable that saves the scale factor?

Thanks in advance.

TOPICS
Actions and scripting
961
Translate
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
Community Expert ,
Sep 19, 2014 Sep 19, 2014

I just tested in Photoshop CC and there the result of scaling a Type Layer seems to be a Type Layer with the correspondingly larger/smaller type size. (edited)

Translate
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
New Here ,
Sep 19, 2014 Sep 19, 2014

Thanks! That's right, and I'd like to know if there's a scale value inside the layer, accessible through scripting.

I'll explain the problem a bit: in CC, when you do what I explain in the opening post, you can see in the interface a bigger value for the text size, but when you get "layer.textItem.size" through scripting, the size is the original one, not the one you see in the interface (the bigger). That didn't happen in CS5.

So I was thinking if it might be possible to calculate the new text size of the layer with that original text size * the layer scale factor (in case there's a variable that has that value).

Translate
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 ,
Sep 19, 2014 Sep 19, 2014

Does this help?

// get keys for type layer stuff;

// based on code by michael l hale;

// 2014, use it at your own risk;

#target "photoshop-70.032"

if (app.documents.length > 0) {

if (app.activeDocument.activeLayer.kind == LayerKind.TEXT) {

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var layerDesc = executeActionGet(ref);

var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));

checkDesc2 (textDesc.getObjectValue(stringIDToTypeID("transform")));

}

};

//////

////// based on code by michael l hale //////

function checkDesc2 (theDesc) {

var c = theDesc.count;

var str = '';

for(var i=0;i<c;i++){ //enumerate descriptor's keys

  str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';

  };

alert("desc\n\n"+str);

};

////// check //////

function getValues (theDesc, theNumber) {

switch (theDesc.getType(theDesc.getKey(theNumber))) {

case DescValueType.BOOLEANTYPE:

return theDesc.getBoolean(theDesc.getKey(theNumber));

break;

case DescValueType.CLASSTYPE:

return theDesc.getClass(theDesc.getKey(theNumber));

break;

case DescValueType.DOUBLETYPE:

return theDesc.getDouble(theDesc.getKey(theNumber));

break;

case DescValueType.ENUMERATEDTYPE:

return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));

break;

case DescValueType.INTEGERTYPE:

return theDesc.getInteger(theDesc.getKey(theNumber));

break;

case DescValueType.LISTTYPE:

return theDesc.getList(theDesc.getKey(theNumber));

break;

case DescValueType.OBJECTTYPE:

return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));

break;

case DescValueType.REFERENCETYPE:

return theDesc.getReference(theDesc.getKey(theNumber));

break;

case DescValueType.STRINGTYPE:

return theDesc.getString(theDesc.getKey(theNumber));

break;

case DescValueType.UNITDOUBLE:

return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));

break;

default:

break;

};

};

edited

Translate
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 ,
Sep 19, 2014 Sep 19, 2014

Please note I edited the code, I had omitted a line.

Translate
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 ,
Sep 21, 2014 Sep 21, 2014

There seems to be a problem with

textDesc.getObjectValue(stringIDToTypeID("transform"))

Capture.jpg

JJMack
Translate
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 ,
Sep 21, 2014 Sep 21, 2014

Has the Layer been transformed at all?

Otherwise there would be no need for the key, I guess; either using hasKey() or wrapping it in a try-clause should work.

Translate
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 ,
Sep 21, 2014 Sep 21, 2014

Understood I'll just put it in a try

JJMack
Translate
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 ,
Sep 21, 2014 Sep 21, 2014

I should have thought of that …

Translate
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
Enthusiast ,
Sep 21, 2014 Sep 21, 2014

Note that CC2014 works differently from CC2012 and I've not found a reliable way for CS6. This is the code I have for getting the paragraph text box extents.

getTextExtentsCC2014: function (text_item) {

        app.activeDocument.activeLayer = text_item.parent

        var ref = new ActionReference()

        ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") )

        var action = executeActionGet(ref)

        var textKey = action.getObjectValue(stringIDToTypeID('textKey'))

        var bounds = textKey.getObjectValue(stringIDToTypeID('bounds'))

        var width = bounds.getUnitDoubleValue (stringIDToTypeID('right'))

        var height = bounds.getUnitDoubleValue (stringIDToTypeID('bottom'))

        var x_scale = 1

        var y_scale = 1

        if (textKey.hasKey(stringIDToTypeID('transform'))) { 

            var transform = textKey.getObjectValue(stringIDToTypeID('transform'))

            x_scale = transform.getUnitDoubleValue (stringIDToTypeID('xx'))

            y_scale = transform.getUnitDoubleValue (stringIDToTypeID('yy'))

        }

        x_scale *= width / text_item.width

        y_scale *= height / text_item.height

        return {

            x:Math.round(text_item.position[0]),

            y:Math.round(text_item.position[1]),

            width:Math.round(width*x_scale),

            height:Math.round(height*y_scale) }

},
getTextExtentsCC2012: function (text_item) {

        app.activeDocument.activeLayer = text_item.parent

        var ref = new ActionReference()

        ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") )

        var action = executeActionGet(ref)

        var textKey = action.getObjectValue(stringIDToTypeID('textKey'))

        var bounds = textKey.getObjectValue(stringIDToTypeID('bounds')) 

        var width = bounds.getUnitDoubleValue (stringIDToTypeID('right')) 

        var height = bounds.getUnitDoubleValue (stringIDToTypeID('bottom')) 

        var x_scale = 1

        var y_scale = 1

        if (textKey.hasKey(stringIDToTypeID('transform'))) { 

            var transform = textKey.getObjectValue(stringIDToTypeID('transform'))

            x_scale = transform.getUnitDoubleValue (stringIDToTypeID('xx'))

            y_scale = transform.getUnitDoubleValue (stringIDToTypeID('yy'))

        }

        return {

            x:Math.round(text_item.position[0]),

            y:Math.round(text_item.position[1]),

            width:Math.round(width*x_scale),

            height:Math.round(height*y_scale)

            }

},
Translate
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
New Here ,
Sep 22, 2014 Sep 22, 2014
LATEST

Thanks for the replies. I'll give it a go during the week

Translate
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