Skip to content

Instantly share code, notes, and snippets.

@codenamezjames
Created May 31, 2021 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codenamezjames/13aaf41c776d016cd1be955544dd8754 to your computer and use it in GitHub Desktop.
Save codenamezjames/13aaf41c776d016cd1be955544dd8754 to your computer and use it in GitHub Desktop.
Bulk rename layers in illustrator by selected index
var LayerRenamer, layerRenamer;
function range(start, end) {
var foo = [];
for (var i = start; i <= end; i++) {
foo.push(i);
}
return foo;
}
LayerRenamer = (function() {
function LayerRenamer() {
if (app.activeDocument.selection.length > 0) {
this.replacements = prompt('Replacement Strategy? EG: "a" OR "1" (starting number) OR coma separated custom values ab,cd,ef,gh... 1,3,5,7,8,9 ', 1)
if (!this.replacements) return
this.renameLayers(app.activeDocument.selection);
} else {
alert("Select the layers you would like to be renamed.");
}
}
LayerRenamer.prototype.renameLayers = function(layers) {
var layer, _i, _len, _results, customArr;
_results = [];
for (_i = 0, _len = layers.length; _i < _len; _i++) {
layer = layers[_i];
type = this.replacements
customArr = type.split(',')
if (customArr && customArr.length >= 5) {
type = customArr
} else if (type === 'a') {
type = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
} else if (typeof (+type) === 'number') {
type = range(type, type + 999)
} else {
type = range(type, type + 999)
}
_results.push(layer.name = typeof type[_i] !== 'undefined' ? type[_i] : _i);
}
return _results;
};
return LayerRenamer;
})();
layerRenamer = new LayerRenamer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment