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

How to get the width/height of a layer in a script

Community Beginner ,
Nov 27, 2020 Nov 27, 2020

Hello all, I am trying to make a small script that resizes a layer (shrinking) to fit the canvas/image size... I am trying to do this by querying both the document width/height then comparing it to the layer width/height, but I cannot find any way to find the layer width/height... any suggestions? I have tried the code below but it brings back an 'undefined'.

app.preferences.rulerUnits = Units.PIXELS;
var docHeight = app.activeDocument.height;
//alert(docHeight);

var docWidth = app.activeDocument.width;
//alert(docWidth);

var layerWidth = app.activeDocument.activeLayer.width;
alert(layerWidth);
//this line above returns the 'undefined"

 How can I get the activeLayer width and height?

 

Thanks!

TOPICS
Actions and scripting
5.3K
Translate
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

correct answers 1 Correct answer

Community Expert , Nov 27, 2020 Nov 27, 2020
var theBounds = app.activeDocument.activeLayer.bounds;
var layerWidth = theBounds[2] - theBounds[0];
var layerHeight = theBounds[3] - theBounds[1];
Translate
Adobe
LEGEND ,
Nov 27, 2020 Nov 27, 2020

It's layer.bounds. I'm not into PS scripting, but I know at least that much. Hope it helps.

 

Mylenium

Translate
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 ,
Nov 27, 2020 Nov 27, 2020
var theBounds = app.activeDocument.activeLayer.bounds;
var layerWidth = theBounds[2] - theBounds[0];
var layerHeight = theBounds[3] - theBounds[1];
Translate
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 ,
Nov 27, 2020 Nov 27, 2020

 

 

+ - - - - - - - 1 - - - - - - - +
|                               |
|                               |
|                               |
0                               2
|                               |
|                               |
|                               |
+ - - - - - - - 3 - - - - - - - +

 

 

 

Thanks SuperMerlin!

 

Translate
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
Guide ,
Nov 27, 2020 Nov 27, 2020
LATEST

It's Left, Top, Right and Bottom

Translate
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