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

How do I get the W and H

Explorer ,
May 10, 2024 May 10, 2024

Copy link to clipboard

Copied

I use the following script to get the rotation angle in the transform panel. How do I get the W and H values?

function angleFromMatrix(yy, xy)
{
    var toDegs = 180/Math.PI;
    return Math.atan2(yy, xy) * toDegs - 90;
}

function getActiveLayerRotation()
{
    var ref = new ActionReference();
    ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'))
    if (desc.hasKey(stringIDToTypeID('transform')))
    {
        desc = desc.getObjectValue(stringIDToTypeID('transform'))
        var yy = desc.getDouble(stringIDToTypeID('yy'));
        var xy = desc.getDouble(stringIDToTypeID('xy'));
        return angleFromMatrix(yy, xy);
    }
    return 0;
}

getActiveLayerRotation()

WH.png

 

TOPICS
Actions and scripting

Views

209

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
Community Expert ,
May 10, 2024 May 10, 2024

Copy link to clipboard

Copied

Using the layer or selection bounds is one method, depending on the specifics of the object (i.e. with or without effects):

 

var origRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var layerBounds = activeDocument.activeLayer.bounds;
var layerWidth = layerBounds[2].value - layerBounds[0].value;
var layerHeight = layerBounds[3].value - layerBounds[1].value;
alert(layerWidth + " x " + layerHeight);
app.preferences.rulerUnits = origRulerUnits;

 

or

 

var layerBounds = activeDocument.activeLayer.bounds;
var layerWidth = layerBounds[2].as('px') - layerBounds[0].as('px');
var layerHeight = layerBounds[3].as('px') - layerBounds[1].as('px');
alert(layerWidth + " x " + layerHeight);

 

There might be a more direct method using AM code, but that is above my knowledge.

 

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 ,
May 10, 2024 May 10, 2024

Copy link to clipboard

Copied

thank you very much for your 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
People's Champ ,
May 12, 2024 May 12, 2024

Copy link to clipboard

Copied

LATEST

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-get-text-transform-box-boundar...

 

You are interested in the rectangle P2, or rather its boundaries l, t, r ,b from which you will get the width (r-l) and height (b-t). All values are in points units.

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