Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
2

I need script to select the the specific layer if that is empty also

Community Beginner ,
Aug 10, 2023 Aug 10, 2023

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.

TOPICS
Scripting
168
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 10, 2023 Aug 10, 2023

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

Translate
Adobe
Guide ,
Aug 10, 2023 Aug 10, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 10, 2023 Aug 10, 2023
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines