Detecting a layer by name
The following code is part of a larger script. I'm trying to detect if the layer "Canons Grid" exists. If it doesn't then create a new layer with that name. This code fails everytime, even if the layer doesn't exist. What am i doing wrong?
var doc = app.activeDocument;
var canonLayer;
try {
canonLayer = doc.layers.itemByName("Canons Grid");
}
catch(e)
{
canonLayer = doc.layers.add({name: "Canons Grid"});
}