How to find angle of rotation of photoshop layer

When using the Photoshop API to work with layers, getting the rotation angle directly from the layer information isn’t straightforward. The API typically doesn’t include rotation data in its basic layer details. The only information that was received was a transformation matrix which was obtained using a plugin called Alchemist. How can we find the rotation angle using this transformation matrix?
Does anyone has insights or experience with using batchPlay commands or other techniques to retrieve rotation angle in degrees of a layer through the Photoshop API ? Your input would be greatly appreciated!

I found a way to get the current rotation angle for a text layer. More precisely, I adapted the method from ExtendScript to UXP.

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;
}

This works in JSX.

async function getActiveLayerRotationAngle() {
    const app = require("photoshop").app;
    const activeDocument = app.activeDocument;
    const activeLayer = activeDocument.activeLayers[0];
    
    const layerId = activeLayer._id;
    const transform = await batchPlay([
        {
            "_obj": "get",
            "_target": [{ "_ref": "layer", "_id": layerId }],
            "_property": "transform"
        }
    ], {});
    const { textKey: { transform: { yy, xy } } } = transform[0];
    const toDegs = 180 / Math.PI;
    const angle = Math.atan2(yy, xy) * toDegs - 90;
    console.log("angle=" + angle);
    return angle;
}

This works in UXP.

I was specifically looking for a method for text layers.

1 Like