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

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

235

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 

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
LEGEND ,
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

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 ,
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)

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

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