Rename Layers All Items

Script for Adobe Illustrator

Renames layers and all items to incrementing numbers.

  • Begins at 001 and increments
  • Adapt open source to customize or create other scripts
Download
Rename Layers All Items
Help me keep making new scripts by supporting my work. Click the PayPal button to contribute any amount you choose. Thank you. William Campbell

How to use the script

The interface has no interface. Run the script and starting from the top, every layer and item within it are renamed to a 3-digit number beginning at 001.

Source code

(download button below)

(function () {

var n = 1;
if (!app.documents.length) {
    alert("Open a document");
    return;
}
walkLayers(app.activeDocument);
alert("Done");

function padZero(v) {
    return ("00" + v).slice(-3);
}

function walkLayers(o) {
    var i;
    var layer;
    for (i = 0; i < o.layers.length; i++) {
        layer = o.layers[i];
        layer.name = padZero(n++);
        walkLayers(layer);
        if (layer.pageItems.length) {
            walkPageItems(layer);
        }
    }
}

function walkPageItems(o) {
    var i;
    var item;
    for (i = 0; i < o.pageItems.length; i++) {
        item = o.pageItems[i];
        item.name = padZero(n++);
        if (item.constructor.name == "GroupItem") {
            walkPageItems(item);
        }
    }
}

})();
Help me keep making new scripts by supporting my work. Click the PayPal button to contribute any amount you choose. Thank you. William Campbell
Download
Rename Layers All Items

For help installing scripts, see How to Install and Use Scripts in Adobe Creative Cloud Applications.

IMPORTANT: scripts are developed for the latest Adobe Creative Cloud applications. Many scripts work in CC 2018 and later, even some as far back as CS6, but may not perform as expected, or run at all, when used in versions prior to 2018. Photoshop features Select Subject and Preserve Details 2.0 definitely fail prior to CC 2018 (version 19) as the features do not exist in earlier versions. For best results use the latest versions of Adobe Creative Cloud applications.

IMPORTANT: by downloading any of the scripts on this page you agree that the software is provided without any warranty, express or implied. USE AT YOUR OWN RISK. Always make backups of important data.

IMPORTANT: fees paid for software products are the purchase of a non-exclusive license to use the software product and do not grant the purchaser any degree of ownership of the software code. Author of the intellectual property and copyright holder William Campbell retains 100% ownership of all code used in all software products regardless of the inspiration for the software product design or functionality.