Skip to main content
Known Participant
May 13, 2015
Answered

Prenamed Layers

  • May 13, 2015
  • 3 replies
  • 520 views

Does anybody know of a script that generates a fixed number of layers with predefined names? in a specific order from top to bottom of the stack?

Many thanks

Sean

This topic has been closed for replies.
Correct answer Qwertyfly___

I am sure you can nut out how to add your own Layer names and number of layers.

This does not remove any current layers in the document.

existing layers are left at the bottom.

var LayersList = [

    '1st Layer',

    '2nd Layer',

    '3rd Layer',

    '4th Layer',

    '5th Layer',

    'Last Layer'

];

var doc = app.activeDocument;

for(var i = LayersList.length-1; i > -1; i--){

    var newLayer = doc.layers.add();

    newLayer.name = LayersList;

}

3 replies

Qwertyfly___
Qwertyfly___Correct answer
Legend
May 13, 2015

I am sure you can nut out how to add your own Layer names and number of layers.

This does not remove any current layers in the document.

existing layers are left at the bottom.

var LayersList = [

    '1st Layer',

    '2nd Layer',

    '3rd Layer',

    '4th Layer',

    '5th Layer',

    'Last Layer'

];

var doc = app.activeDocument;

for(var i = LayersList.length-1; i > -1; i--){

    var newLayer = doc.layers.add();

    newLayer.name = LayersList;

}

Known Participant
May 14, 2015

WOW! I bow to your superpowers. This could not be more perfect and I'm very grateful for your help.

Inspiring
May 13, 2015

So, why not just write one? If the naming convention is fairly sequential, us a loop to create the layers and name them accordingly right in the loop. If the names are more unique, then use an array for the names, and in the loop create the layers and pull the names from the array. Look at the scripting guide and find general js tutorials if needed for things, then ask here for specific help when you need it further.

Larry G. Schneider
Community Expert
Community Expert
May 13, 2015

Considering doing it with a New Document Profile.

Known Participant
May 13, 2015

Thanks Larry, I thought of that but the nature of our work makes it more practical to fire a script in an existing file.