# Access SmartObject transform properties?

**URL:** <https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349>\
**Category:** UXP Plugin API\
**Created:** [October 15, 2022, 11:30am UTC](https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349 "2022-10-15T11:30:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ProfL](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/profl/32/2416_2.png) [@ProfL](https://forums.creativeclouddeveloper.com/u/ProfL)\
**Post date:** [October 15, 2022, 11:30am UTC](https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349/1 "2022-10-15T11:30:55Z")

</div>

Hi All, Is there any way to access the current transform properties of a smart object? I’m trying to make a real-time slider for rotating and scaling multiple smart objects… But I’m finding that using relative rotation and scale makes for unreliable results. Thanks!

 ![Screen Shot 2022-10-14 at 8.34.56 PM](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/0/0e7ec0600345bc64f471c3f4e43b49abdf1a1685.png)

---

<div class="post-metadata">

**Author:** ![SkipIntro](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/skipintro/32/2338_2.png) [@SkipIntro](https://forums.creativeclouddeveloper.com/u/SkipIntro)\
**Post date:** [October 17, 2022, 3:57pm UTC](https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349/2 "2022-10-17T15:57:45Z")

</div>

I used to do this with the old ActionDescriptor method. Looks like the “smartObjectMore” property is still accessible via Batchplay.

```auto
function getSmartObjectInfo(layerId, docId) {
	const res = require("photoshop").action.batchPlay(
		[
			{
				_obj: 'get',
				_target: [
					{_ref: "layer", _id: layerId},
					{_ref: "document",_id: docId}
				]
			}
		],
		{ synchronousExecution: true }
	)[0];
	if (res.hasOwnProperty("smartObjectMore")) {
		console.log(res.smartObjectMore);
	} else {
		console.error("Layer with id " + layerId + " is not a smart object");
	}
}

```

This object has a ton of info but it’s not presented in the user-friendly format that the UI displays. _.transform_ has the info you need. They don’t give you rotation or scale. You’ll need to calculate that by comparing the .size to the transform points for scale, and write or find a function that calculates rotation based on four points.

---

<div class="post-metadata">

**Author:** ![ProfL](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/profl/32/2416_2.png) [@ProfL](https://forums.creativeclouddeveloper.com/u/ProfL)\
**Post date:** [October 17, 2022, 9:58pm UTC](https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349/3 "2022-10-17T21:58:06Z")

</div>

Oh. amazing. I genuinely didn’t think there’d be an answer. Greatly appreciated.

---

<div class="post-metadata">

**Author:** ![SkipIntro](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/skipintro/32/2338_2.png) [@SkipIntro](https://forums.creativeclouddeveloper.com/u/SkipIntro)\
**Post date:** [October 17, 2022, 10:12pm UTC](https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349/4 "2022-10-17T22:12:08Z")

</div>

No prob. Although I should mention I read your original post in haste. I’m not certain how reliably you can _set_ Smart Object transforms, but I know you can get all the smart object data.

---

<div class="post-metadata">

**Author:** ![ProfL](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/profl/32/2416_2.png) [@ProfL](https://forums.creativeclouddeveloper.com/u/ProfL)\
**Post date:** [October 18, 2022, 12:41am UTC](https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349/5 "2022-10-18T00:41:57Z")

</div>

Also, actually, I can’t find the rotation data in there. But useful to access position and height width. It looks like there were people trying to figure this out for scripts a few years ago with no luck.

---

<div class="post-metadata">

**Author:** ![SkipIntro](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/skipintro/32/2338_2.png) [@SkipIntro](https://forums.creativeclouddeveloper.com/u/SkipIntro)\
**Post date:** [October 18, 2022, 4:05pm UTC](https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349/6 "2022-10-18T16:05:55Z")

</div>

Yeah no rotation. But you should be able to reliably calculate rotation by using the _smartObjectMore.transform_ array. Also, Photoshop doesn’t give smart objects an anchor point, so the UI shows the position as the center (average) of the 4 corners:

```auto
function rotationFromCorners(points) {
	var A = points.upperLeft;
	var B = points.upperRight;
	var radians = Math.atan2(B.y - A.y, B.x - A.x);
	return radians * (180/Math.PI);
}

function getAvgPointPosition(points) {
	var xa = (points.upperLeft.x + points.upperRight.x + points.lowerRight.x + points.lowerLeft.x)/4;
	var ya = (points.upperLeft.y + points.upperRight.y + points.lowerRight.y + points.lowerLeft.y)/4;
	return {x:xa, y:ya};
}

// BatchPlay smartObjectMore.transform array of a 1920x1080 image
var t = [
	0,
	0,
	1920,
	0,
	1920,
	1080,
	0,
	1080
];

// Parse points from .transform into something more readable
var smartObjectPoints = {
	upperLeft: {x:t[0], y:t[1]},
	upperRight: {x:t[2], y:t[3]},
	lowerRight: {x:t[4], y:t[5]},
	lowerLeft: {x:t[6], y:t[7]}
};

var smartObjectRotation = rotationFromCorners(smartObjectPoints);
var smartObjectPosition = getAvgPointPosition(smartObjectPoints);

```

Keep in mind you may start to get inaccuracies from a simple 2-point rotation calculation if you start to throw stuff like _Transform \> Skew/Distort/Perspective_ into the mix. Then you may need to compare .transform to the _smartObjectMore.nonAffineTransform_ data. It can get a little tricky, but if you know you’ll be dealing with mostly just basic SO transforms, using the corners should be consistent.

---

<div class="post-metadata">

**Author:** ![photonic](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/photonic/32/2513_2.png) [@photonic](https://forums.creativeclouddeveloper.com/u/photonic)\
**Post date:** [December 6, 2023, 12:26am UTC](https://forums.creativeclouddeveloper.com/t/access-smartobject-transform-properties/5349/7 "2023-12-06T00:26:42Z")

</div>

In case someone needs it, I made a function to get the scale in percentage using the points info so we can have the complete transformation properties:

```auto
function getScaleFromPoints(points, fullSize) {
        const A = points.upperLeft;
        const B = points.upperRight;
        const C = points.lowerLeft;

        const w = distance([A.x, A.y], [B.x, B.y]);
        const h = distance([A.x, A.y], [C.x, C.y]);

        const fullWidth = fullSize.width;
        const fullHeight = fullSize.height;

        const wP = (w * 100) / fullWidth;
        const hP = (h * 100) / fullHeight;

        return {
          width: wP,
          height: hP
        }

        function distance(a, b) {
          var AB = [b[0] - a[0], b[1] - a[1]];
          return Math.sqrt(AB[0] * AB[0] + AB[1] * AB[1]);
        }
      }

```
