Copy link to clipboard
Copied
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?
1 Correct answer
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 ("An
...Explore related tutorials & articles
Copy link to clipboard
Copied
Hi
I've moved your post to the Photoshop Scripting forum where you are more likely to get an answer to your question
Dave
Copy link to clipboard
Copied
Thanks a lot Dave
Salitha
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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); }
}
Copy link to clipboard
Copied
In a video animation how do you tie that to the timeline where the layer may be be being transformed with rotation, and how do you get the scaling factors?
Copy link to clipboard
Copied
Thanks, r-bin.
On CC2017 it works.
On CC2014 and CC2015 it doesn't.
I am looking for a solution Photoshop 2014CC onwards.
Salitha
Copy link to clipboard
Copied
You can add a rectangular linked vector mask with zero density to the original layer, not an objectively smart object, with dimensions as the layer. Then, after any transformation or rotation, you can calculate the angles and dimensions using 4 points of the vector mask.
I'm not sure that it will be convenient for you.
ps. hope you understand my poor english )
Copy link to clipboard
Copied
The script fails in CC 2014 in followind statement for smartObjectMore does not seem to exist in CC 2014.
d = d.getObjectValue(stringIDToTypeID("smartObjectMore"));
Copy link to clipboard
Copied
smartObjectMore was added in 2015.5
Copy link to clipboard
Copied
Hello, thanks for answer. I just want to know how can we use this inside a loop, iterating through all the layers instead of just Trgt.
Copy link to clipboard
Copied
I have been looking for a solution to get the rotation of all the layers. This code actually worked but it targets the active layer only. I want to iterate through all the layers and get their rotation angle.
Copy link to clipboard
Copied
angle is got but how can get scale? any one know?thanks
Copy link to clipboard
Copied
perfect solution!
var smartLayerBounds = getSmartObjectBounds(_layer);//get bound
openSmartObject(_layer);
var smartTargetLayerSourceBounds = getOpenSmartSourceBounds(_layer)
var scale = getScale(smartLayerBounds, smartTargetLayerSourceBounds);
Copy link to clipboard
Copied
What if the Smart Object has been rotated?
Copy link to clipboard
Copied
Thanks for the solve! Out of curiosity, are you able to record "smartObjectMore" with scripting listener? Just wondering where this info is stored and how it was found.
Copy link to clipboard
Copied
What do you mean by »record« exactly?
It is certainly possible to get the values from an existing Smart Object.
// based on code by michael l hale;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var soDesc = layerDesc.getObjectValue(stringIDToTypeID('smartObject'));
var soMoreDesc = layerDesc.getObjectValue(stringIDToTypeID('smartObjectMore'));
var transform = soMoreDesc.getList(stringIDToTypeID("transform"));
checkDesc2(soMoreDesc)
};
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
};
alert("desc\n\n"+str);
};
////// check //////
function getValues (theDesc, theNumber) {
switch (theDesc.getType(theDesc.getKey(theNumber))) {
case DescValueType.ALIASTYPE:
return theDesc.getPath(theDesc.getKey(theNumber));
break;
case DescValueType.BOOLEANTYPE:
return theDesc.getBoolean(theDesc.getKey(theNumber));
break;
case DescValueType.CLASSTYPE:
return theDesc.getClass(theDesc.getKey(theNumber));
break;
case DescValueType.DOUBLETYPE:
return theDesc.getDouble(theDesc.getKey(theNumber));
break;
case DescValueType.ENUMERATEDTYPE:
return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
break;
case DescValueType.INTEGERTYPE:
return theDesc.getInteger(theDesc.getKey(theNumber));
break;
case DescValueType.LISTTYPE:
return theDesc.getList(theDesc.getKey(theNumber));
break;
case DescValueType.OBJECTTYPE:
return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
break;
case DescValueType.REFERENCETYPE:
return theDesc.getReference(theDesc.getKey(theNumber));
break;
case DescValueType.STRINGTYPE:
return theDesc.getString(theDesc.getKey(theNumber));
break;
case DescValueType.UNITDOUBLE:
return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
break;
default:
break;
};
};
Copy link to clipboard
Copied
What do you mean by »record« exactly?
Record/log through scripting listener. Sorry, I meant to specify that. I'm trying to understand how you'd find that through AM, if undocumented and not logged/recorded. It seems to only be informational, so photoshop doesn't find it necessary to place in an AM script.
Copy link to clipboard
Copied
You can get that information so I do not understand what the problem is.
What is the actual scenario in which you need to assess or utilize that information?
Copy link to clipboard
Copied
I'm just trying to understand how to obtain some of these more obscure items on my own. It can help to understand how to edit code and what it is doing. I don't generally like AM, because it's not intuitive to use, but we're forced to since it has more functionality. AM and Extendscript can be a mystery, even with the documentation people have created.
Doesn't seem like there's a way to obtain it with scripting listener, forums are always a great help though.
Copy link to clipboard
Copied
Did you even try the code I posted with a Smart Object selected?
If you need to get the values from any of those keys you can progress from »smartObjectMore«.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.

