Delete a specific layer, depending on its name
greetings everyone,
I'm struggling with a not so difficult problem (I guess).
I need to delete two layers from my document, one named "SIGNATURE" and the other one named with the title of the document.
The problem is that sometimes, the layer won't be present (that's why I've added the makeActiveByName function) but also sometimes, the layer will be into a sublayer (with a different sublayer name for each document ... ).
How can I ask to search and delete the layer trough all the artlayers, including the sub-layers ??
The best might be to move every sub-layer from layerset to the document.
Many thanks in advance ![]()
So the code is :
// Set the makeActiveByName function
function makeActiveByName( lyrName ){
try{
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( charIDToTypeID( "Lyr " ), lyrName );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
return activeDocument.activeLayer;
}catch(e){}
};
// Create the Layer set "CALQUES"
var CALQUES = doc.layerSets.add();
CALQUES.name = 'CALQUES';
// Delete the Signature (if present)
var targetLayer = makeActiveByName("SIGNATURE");// returns undefined if layer not found
if(undefined!=targetLayer){;// if layer was found
doc.artLayers.getByName("SIGNATURE").remove();
}
// Delete the Title (if present)
var DocName = doc.name
var DocNameshort = DocName.left(6)
var targetLayer = makeActiveByName(DocNameshort);
if(undefined!=targetLayer){
doc.artLayers.getByName(DocNameshort).remove();
}
