Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
1

Extracting the scale (as a percentage) of a selected Smart Object

Explorer ,
Jul 25, 2023 Jul 25, 2023

Copy link to clipboard

Copied

Hi all,

 

I've just discovered a handy little function in Photoshop I never knew existed ... 'Convert to Layers'. I'm pretty sure this wasn't always available, but now it is, want to make a simple script to convert the selected Smart Object back into layers again. I need to work out a way of extracting the scale (as a percentage) of the Smart Object before I can go any further, as this information can then be applied to the converted layers, to ensure the dimensions are the same as the original Smart Object. I'm currently working with applescript, but am happy to work with javascript too. The example below extracts some layer details but not the ones I want in the attached screen, which is exactly what I'm struggling with at the moment...

tell application "Adobe Photoshop 2023"
	tell current document
		return properties of current layer
	end tell
end tell

 

Screenshot 2023-07-25 at 14.24.38.png

 

Any help would be appreciated!

 

Cheers,

Sam

TOPICS
Actions and scripting , macOS

Views

293
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jul 25, 2023 Jul 25, 2023

Copy link to clipboard

Copied

Have you seen JJMack’s posts on this thread? 

Check the later posts, the thread originated before Smart Object-transform was accessible via Scripting. 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-can-i-retrieve-the-transform-info...

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 26, 2023 Jul 26, 2023

Copy link to clipboard

Copied

LATEST

Thanks @c.pfaffenbichler I didn't see this!

Using a mixture of applescript and javascript you supplied reference to, I managed to extract the horizontal and vertical scale from the smart object, which is great news! I've not considered rotation or warping of the smart object, but have a feeling this might be something I look into down the line. However, the resolution inside and outside the Smart Object is considered, and it's not assumed they're the same...

 

Smart Object Dimensions (smartObjInnerWidth smartObjInnerHeight😞

 

var smartObjectScan = new ActionReference();
smartObjectScan.putEnumerated(charIDToTypeID( 'Lyr ' ), charIDToTypeID( 'Ordn' ), charIDToTypeID( 'Trgt' ));
with (executeActionGet(smartObjectScan).getObjectValue(stringIDToTypeID('smartObjectMore')))  
		var dimensions = getObjectValue(stringIDToTypeID('size'));
	
		var size = new Object({
		w: dimensions.getDouble(stringIDToTypeID('width')),  
		h: dimensions.getDouble(stringIDToTypeID('height')),  
});
size.toSource()

 

 

Smart Object Resolution (smartObjInnerRes😞

 

var smartObjectScan = new ActionReference();
smartObjectScan.putEnumerated(charIDToTypeID( 'Lyr ' ), charIDToTypeID( 'Ordn' ), charIDToTypeID( 'Trgt' ));
with (executeActionGet(smartObjectScan).getObjectValue(stringIDToTypeID('smartObjectMore')))  
			var resolution = getUnitDoubleValue(stringIDToTypeID('resolution'));  
(resolution)

 

Using applescript to extract the document resolution (docRes) and the smart object layer dimensions (smartObjWidth & smartObjHeight) I was then able to create the following calculations, which gives the percentage scale for both the height and width of the smart object...

The Resolution Ratio (resRatio) is found by dividing the smart object resolution by the canvas resolution... This either gives 1 (if they're the same resolutions) or a fraction, which is used to give the final scale reading at the end:

set resRatio to smartObjInnerRes / docRes

 

The horizontal (smartObjHorizScale) and vertical (smartObjVertScale) scales are found out by working out the percentage difference between the Smart Object's dimensions, inside (smartObjInnerWidthsmartObjInnerHeight) and outside (smartObjWidth & smartObjHeight). This number is multiplied by the Resolution Ratio to ensure the reading is accurate.

 

set smartObjHorizScale to resRatio * (100/smartObjInnerWidth * smartObjWidth)
set smartObjVertScale to resRatio * (100/smartObjInnerHeight * smartObjHeight)

 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines