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

49

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 , 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; }

Likes

Translate

Translate
Adobe Community Professional ,
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

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

Copy link to clipboard

Copied

LATEST

Thank you so much @Charu Rajput 

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