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

Finding the dimensions of a smart object, even when the smart object contains negative space...

Explorer ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

Hi all,

 

I'm trying to find the true dimensions of a smart object layer in Photoshop... The following piece of applescript works as long as there is no negative space in the smart object. If there is negative space, the following is no longer accurate. You can click on the layer and it shows what the below applescript is seeing, however, clicking on a corner of the layer can sometimes reveal more than what is being shown originally.

 

tell application "Adobe Photoshop 2023"
	
	tell current document
		
		set smartObjectDimensions to bounds of current layer
		set smartObjectWidth to (item 3 of smartObjectDimensions) - (item 1 of smartObjectDimensions)
		set smartObjectHeight to (item 4 of smartObjectDimensions) - (item 2 of smartObjectDimensions)
		
	end tell
	
end tell

 

Any help would be much appreciated!

 

Cheers,

Sam

TOPICS
Actions and scripting , macOS

Views

224

Translate

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 ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

I don't use AS, is "set" correct and not "get"? Anyway, it's easy in JS and AS can run JS:

 

https://gist.github.com/MarshySwamp/ef345ef3dec60a843465347ee6fcae2f

 

The wrinkle is always layer effects such as drop shadows or glow, one has to dupe, rasterize, get bounds and calculate the width and height.

 

P.S. Can you provide a sample PSD file to illustrate?

Votes

Translate

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 ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

Hi @Stephen_A_Marsh , thanks for your response! I'm always up for using Javascript in my Applescripts, but both options still return the same result, as it ignores the empty space around it. So, to hopefully explain my example, I have a smart object here, which when highlighted, only shows the space with pixels in. These are the dimensions which are stripped from the layer when using my Applescript, as well as the Javascript you recommended.

Screenshot 2023-08-11 at 09.59.40.png

Yet, when I click on the corner to enlarge it, the true size of the smart object appears, which includes all negative space too. I know how to extract the smart object size without opening it, but I need to know the size of the smart object as it is on this image, as scaling etc may have happened. If I was to triggger the script on the layer in the below state, it hangs, as it assumes Photoshop is busy doing something.

 

Screenshot 2023-08-11 at 09.59.48.png

 

Regarding your first comment, I always use 'set' to retrive any variables... I don't ever use 'get'. If I'm testing anything I do use 'return' after I've used 'set' which stops the script at that point, returning the variable in question.

Votes

Translate

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
Community Expert ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

I'm sure that this has been covered previously, but where?

Votes

Translate

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
Community Expert ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

LATEST
// 2023, 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"));
var xx = new Array;
for (var m = 0; m < transform.count; m++) {
xx.push(transform.getDouble(m))
};
alert ("\n"+xx.join("\n"));
};

Votes

Translate

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