How to validate that particular layer has image in it ?

Explorer ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

Capture.PNG

My question is how to validate that particular layer has Image. Like we can see , it is image as showing in   Control Panel. In my code  

var lar1 = app.activeDocument.layers[0].layers;
alert(lar1);
output i am getting is [Layers]. But i need to validate if this layer has image or not.
Secondly To validate Layer 1 Image_1 has two sublayer , my code is - 
var lar2 = app.activeDocument.layers["Layer 1 Image_1"].length ;
This is niot working.Any idea how to validate if parent layer has two sub layer .
 
Thanks in advance!
TOPICS
Scripting

Views

37

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Aug 03, 2022 Aug 03, 2022

HI,

I am not sure what excatly are you looking for. Im your screenshots there is no sublayer. 

 

1. To get an Image

As per your screenshot, you can get an image if it is raster like below

var lar1 = app.activeDocument.layers[0];
var _image = lar1.rasterItems[0];

if it is a linked file then as

var lar1 = app.activeDocument.layers[0];
var _image = lar1.placedItems[0];

 

2. To check if layer has two syblayers

var lar1 = app.activeDocument.layers[0];
var _subLayers = lar1.layers;
if(_subLayers.lengt
...

Likes

Translate

Translate
Adobe Community Professional ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

HI,

I am not sure what excatly are you looking for. Im your screenshots there is no sublayer. 

 

1. To get an Image

As per your screenshot, you can get an image if it is raster like below

var lar1 = app.activeDocument.layers[0];
var _image = lar1.rasterItems[0];

if it is a linked file then as

var lar1 = app.activeDocument.layers[0];
var _image = lar1.placedItems[0];

 

2. To check if layer has two syblayers

var lar1 = app.activeDocument.layers[0];
var _subLayers = lar1.layers;
if(_subLayers.length == 2){
    alert('Two sublayers exists');
}

 

Best regards

Likes

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 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

LATEST

Thank you for the reply !!!

Likes

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