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()
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.
Copy link to clipboard
Copied
thank you very much for your help
Copy link to clipboard
Copied
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.