Skip to main content
Inspiring
May 11, 2024
Question

How do I get the W and H

  • May 11, 2024
  • 2 replies
  • 428 views

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

 

This topic has been closed for replies.

2 replies

Legend
May 12, 2024

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-get-text-transform-box-boundary/m-p/11142715

 

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.

Stephen Marsh
Community Expert
Community Expert
May 11, 2024

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.

 

javaerAuthor
Inspiring
May 11, 2024

thank you very much for your help