Copy link to clipboard
Copied
I need a Script for select the xyz layer, if that layer is empty also, I just wanted to select that particular layer, after select that layer I want to move that layer to top and to make sure that layer has been selected when that script ended. if in case that xyz layer not available in artwork, i want to create the xyz layer and to keep that on top of all layers, and to select that layer when script ended. Can anybody help me to prepare this script.
1 Correct answer
The following might work, change the name of the layer you need to find in the 1st line of the code
var layerName = "xy"
try{
var lyr = app.documents[0].layers.getByName(layerName)
}catch(e){
lyr = app.documents[0].layers.add()
lyr.name = layerName
}
lyr.move(app.documents[0], ElementPlacement.PLACEATBEGINNING)
app.activeDocument.activeLayer = lyr
-Manan
Explore related tutorials & articles
Copy link to clipboard
Copied
Just to define the problem more clearly, is this what you want to do (notwithstanding "selecting" the layer)?
Test if a layer named "xyz" exists.
(1) If this layer exists:
(a) If this layer is empty (no pageItems and no sublayers), move this layer to the top.
(b) If this layer is not empty, do nothing.
(2) If this layer doesn't exist, add this layer to the top.
Copy link to clipboard
Copied
The following might work, change the name of the layer you need to find in the 1st line of the code
var layerName = "xy"
try{
var lyr = app.documents[0].layers.getByName(layerName)
}catch(e){
lyr = app.documents[0].layers.add()
lyr.name = layerName
}
lyr.move(app.documents[0], ElementPlacement.PLACEATBEGINNING)
app.activeDocument.activeLayer = lyr
-Manan

