Skip to main content
dublove
Legend
May 18, 2026
Answered

How to simultaneously modify layer names and colors?

  • May 18, 2026
  • 2 replies
  • 79 views

make a judgment first:

If the document only has one layer and the layer name is not aa.

I will rename this layer to "aa" and change the color to red
 

 

    Correct answer rob day
    var d = app.activeDocument;
    if (d.layers.length == 1) {
    d.layers[0].properties = {name:"aa", layerColor:UIColors.RED}
    }

     

    2 replies

    dublove
    dubloveAuthor
    Legend
    May 18, 2026

    Hi ​@rob day 

    How to determine if aa is at the lowest level (Location Options. AT-END)

    Thank you very much.

     

    rob day
    Community Expert
    Community Expert
    May 19, 2026

    The layer index goes from top to bottom, so the bottom layer is d.layers[d.layers.length-1]. You would use Location Options if you want to move a layer

     

    var d = app.activeDocument;
    //Bottom layer name
    alert(d.layers[d.layers.length-1].name)
    //Top layer name
    alert(d.layers[0].name)

     

    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    May 18, 2026
    var d = app.activeDocument;
    if (d.layers.length == 1) {
    d.layers[0].properties = {name:"aa", layerColor:UIColors.RED}
    }