for loop with layer name.
I am developing a script that checks if the layer color-101 exists in an open document.
If the layer color-101 exists run code block on layer color-101.
If the layer color-101 does not exist run action add color-101 layer.
Return to beginning of loop to check again
I am doing this with a for loop and if statement.
1. Why does the loop not stop when the loop-counting-variable matches the layer name color-101 variable?
2. How can the loop return to the beginning to check again for the presence of layer color-101?
//Decalre varaibles
docRef = app.activeDocument;
var theLayer = "color-101";
//loop through layers
for(var i = 0; i < docRef.layers.length; i++){
//layer name matches loop variable
if(docRef.layers.name == theLayer){
//Run code block for layer color-101
alert ("The layer " + theLayer + " exist. ");
}
}
//layer color-101 was not found, run action add color-101 layer
alert ("The " + theLayer + " layer does not exist: Run action add color-101 layer.");
//return to beginning of loop and check again
