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

Javascript to check particular layer is available in the Artwork or not

Explorer ,
Jan 24, 2022 Jan 24, 2022

Copy link to clipboard

Copied

Hello Everyone,

 

Currently, I am using the script to hide the Layer "TB"  and lock all layers in the active document:

var document = app.activeDocument;

document.activeLayer = document.layers["TB"]
document.activeLayer.visible = false;

var lc = document.layers.length;
for (var i=1; i<=lc; i++) {
document.layers[i-1].locked = true;
}

 

But in some cases, my document doesnot have the "TB " layer, in that case i need to skip this step and need to run further. 

 

Please give your inputs to overcome this.

TOPICS
Scripting

Views

195

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

Community Expert , Jan 24, 2022 Jan 24, 2022

Hi,

You can use, try and catch.

var document = app.activeDocument;
try {
    document.activeLayer = document.layers["TB"];
    document.activeLayer.visible = false;
} catch (e) {

}
var lc = document.layers.length;
for (var i = 1; i <= lc; i++) {
    document.layers[i - 1].locked = true;
}

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 24, 2022 Jan 24, 2022

Copy link to clipboard

Copied

Hi,

You can use, try and catch.

var document = app.activeDocument;
try {
    document.activeLayer = document.layers["TB"];
    document.activeLayer.visible = false;
} catch (e) {

}
var lc = document.layers.length;
for (var i = 1; i <= lc; i++) {
    document.layers[i - 1].locked = true;
}
Best regards

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 ,
Jan 24, 2022 Jan 24, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much @Charu Rajput 

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