Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Alert when no layers are selected.

Explorer ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Hello,
I want an alert prompt if there are no layers selected. 
I have this to set up my variables.

 

//set variables
myProj = app.project;
myComp = myProj.activeItem;
myLayer = myComp.selectedLayers[0];

//my code

if (myLayer === undefined){
alert ("Select a Layer);
}

 

Ive tried myLayer == 0, and myLayer == null;

 

Any help is appreciated. Thanks!

 

 

TOPICS
Scripting

Views

90

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 ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

i have end quotes on the alert above. Just a typo here 

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
Adobe Community Professional ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Layer selections are arrays. You have to query the size of the array with myLayers.length, not the contents of the collection.

 

Mylenium

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
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

LATEST

var myProj = app.project;
var myComp = myProj.activeItem;
if(!(myComp instaneof CompItem)) alert("please select a layer (active item is not a composition)");
else {

    if(myComp.selectedLayers.length ==0) alert("please select a layer (a comp is active, but there is no layer selected in this active comp)");

}

(I didn't check the code, it might contain typos)

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