Copy link to clipboard
Copied
Is it possible to create a script that locks layers with specific names? All our documents have a 'CMYK' layer and occasionally a 'CMYK TOP' layer.
Hello @Davis_XI,
Here you go...
doc = app.documents[0];
for (var i = 0; i < doc.layers.length; i++){
if (doc.layers[i].name == "CMYK" || doc.layers[i].name == "CMYK TOP"){
doc.layers[i].locked = true;
}
}
Regards,
Mike
Hello @Davis_XI,
you can try either of these variations...
doc = app.documents[0];
try{for (var i = 0; i < doc.layers.length; i++){
if (doc.layers[i].name == "CMYK" || doc.layers[i].name == "CMYK TOP"){
doc.layers[i].locked = true;
}
} }catch(e){}
try{app.activeDocument.layers.item("CMYK").locked = true; app.activeDocument.layers.item("CMYK TOP").locked = true;}catch(e){}
Regards,
Mike
Copy link to clipboard
Copied
Hello @Davis_XI,
Here you go...
doc = app.documents[0];
for (var i = 0; i < doc.layers.length; i++){
if (doc.layers[i].name == "CMYK" || doc.layers[i].name == "CMYK TOP"){
doc.layers[i].locked = true;
}
}
Regards,
Mike
Copy link to clipboard
Copied
Hi Mike, thank you!!!
Copy link to clipboard
Copied
This script is great and works perfectly if I run it with an open file but when I try and add it to my 'Batch Convert' script it errors. Is there an easy fix for this?
Copy link to clipboard
Copied
Hello @Davis_XI,
you can try either of these variations...
doc = app.documents[0];
try{for (var i = 0; i < doc.layers.length; i++){
if (doc.layers[i].name == "CMYK" || doc.layers[i].name == "CMYK TOP"){
doc.layers[i].locked = true;
}
} }catch(e){}
try{app.activeDocument.layers.item("CMYK").locked = true; app.activeDocument.layers.item("CMYK TOP").locked = true;}catch(e){}
Regards,
Mike
Copy link to clipboard
Copied
You're a star, thank you!!!