Skip to main content
salithan73779666
Participating Frequently
October 21, 2017
Answered

Is there any way to retrieve angle and scale information of smart object?

  • October 21, 2017
  • 3 replies
  • 5715 views

I need to retrieve scale and rotation information changes of a smart object in a video animation using a script.

How can I do this?

Correct answer r-bin

on CC2018 it works, on CS6 do not.

function get_smart_object_corners() returns array from 4 corner-points (x,y) of smart object in pixels (value with floating point)

you can caclulate angle and vertical or horisontal dimentions.

))

Code example:

////////////////////////////////////////////////////////////////////////////////////////////

var points = get_smart_object_corners();

var w = points[0][0] - points[1][0];

var h = points[0][1] - points[1][1];

var angle = Math.atan(h/w) * 180.0 / Math.PI;

alert ("Angle is " + angle.toFixed(3) + "°");

////////////////////////////////////////////////////////////////////////////////////////////

function get_smart_object_corners()

    {

    try

        {

        var r = new ActionReference();

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

        var d;

        try { d = executeActionGet(r); } catch (e) { alert(e); return; }

        try { d = d.getObjectValue(stringIDToTypeID("smartObjectMore"));    } catch (e) { alert(e); return; }

        try { d = d.getList(stringIDToTypeID("transform"));                 } catch (e) { alert(e); return; }

        var ret = [[d.getDouble(0),d.getDouble(1)],

                   [d.getDouble(2),d.getDouble(3)],

                   [d.getDouble(4),d.getDouble(5)],

                   [d.getDouble(6),d.getDouble(7)]];

        return ret;

        }

    catch (e) { alert(e); }

    }

3 replies

Jarda Bereza
Inspiring
October 22, 2017

Hi.. check my script "Undeform" Magic scripts for Photoshop

I solved reading most of deformations. Btw rotation and skew are similar. You can rotate object if you apply 2x skew. If you find the way how to solve perspective, please let me know.

r-binCorrect answer
Legend
October 21, 2017

on CC2018 it works, on CS6 do not.

function get_smart_object_corners() returns array from 4 corner-points (x,y) of smart object in pixels (value with floating point)

you can caclulate angle and vertical or horisontal dimentions.

))

Code example:

////////////////////////////////////////////////////////////////////////////////////////////

var points = get_smart_object_corners();

var w = points[0][0] - points[1][0];

var h = points[0][1] - points[1][1];

var angle = Math.atan(h/w) * 180.0 / Math.PI;

alert ("Angle is " + angle.toFixed(3) + "°");

////////////////////////////////////////////////////////////////////////////////////////////

function get_smart_object_corners()

    {

    try

        {

        var r = new ActionReference();

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

        var d;

        try { d = executeActionGet(r); } catch (e) { alert(e); return; }

        try { d = d.getObjectValue(stringIDToTypeID("smartObjectMore"));    } catch (e) { alert(e); return; }

        try { d = d.getList(stringIDToTypeID("transform"));                 } catch (e) { alert(e); return; }

        var ret = [[d.getDouble(0),d.getDouble(1)],

                   [d.getDouble(2),d.getDouble(3)],

                   [d.getDouble(4),d.getDouble(5)],

                   [d.getDouble(6),d.getDouble(7)]];

        return ret;

        }

    catch (e) { alert(e); }

    }

Inspiring
May 23, 2025

I found the atan conversion of rad to deg causes 180 to be read as 0. There might also be other complications I haven't discovered yet, but for now this additional line is fixing the issue:

 

if( points[0][1] > points[1][1] ) angle = ( angle + 180 ) % 360

 

The idea is to compare the y values of the two corners to detect if it's upside down.

davescm
Community Expert
Community Expert
October 21, 2017

Hi

I've moved your post to the Photoshop Scripting forum where you are more likely to get an answer to your question

Dave

salithan73779666
Participating Frequently
October 21, 2017

Thanks a lot Dave

Salitha

JJMack
Community Expert
Community Expert
October 21, 2017

I do not believe it is possible the get the smart Object layer associated transform settings with a Photoshop Script.   You can see the values in Photoshop Tool Option Bar when you Place in an image or you target a smart object layer and use Ctrl+T free transform.  The tool option bar will display the smart object layers current transform settings.

JJMack