Batch‑Layer Renaming & Asset Export in Illustrator with ExtendScript
Reduce manual Illustrator work by automating layer renaming and PNG export with ExtendScript. A step‑by‑step guide, sample script, and best‑practice checklist for batch vector tasks.
20 Jun 2026, 22:56 UTC

Why the Manual Loop Is a Bottleneck
Design teams often hand‑edit dozens of layers, rename them, tweak artboard sizes, and export PNGs or SVGs for web use. In a single Illustrator session that can mean 30–60 minutes of repetitive clicks. When the same set of files lives in a shared folder or a CI pipeline, the risk of human error spikes. The solution is to let Illustrator do the grunt work: ExtendScript, Adobe’s JavaScript‑based automation engine, can iterate over documents, manipulate layers, and trigger built‑in export workflows.
ExtendScript – The Back‑Compatible Engine
ExtendScript is the scripting language that ships with every Illustrator CC release. It follows ECMAScript 3, so you’ll see var instead of let, no arrow functions, and no modules. The engine lives in app, a global object that exposes the document model, menus, and file I/O. Scripts are launched via File > Scripts > Other Script… and run with the same user permissions as Illustrator itself. If you need to run scripts from the command line, you can use illustrator.exe -r script.jsx on Windows or open -a Illustrator script.jsx on macOS.
Getting the Right Reference
Each CC version adds or removes properties. The Illustrator CC 2023 ExtendScript Reference is the definitive source. Always open the Help > ExtendScript Reference in Illustrator to confirm the API surface you’re targeting.
Practical Example: Batch Rename Layers and Export PNGs
Below is a self‑contained script that:
- Iterates over all open documents.
- Renames each layer to a pattern
Layer_01,Layer_02, … - Exports each artboard as a PNG at 300 dpi.
Run it on a duplicated copy of your artwork first. The script writes a simple log to a text file so you can verify what changed.
/* batch_rename_and_export.jsx */
// 1. Prepare a log file
var logFile = new File(Folder.desktop + "/batch_log.txt");
logFile.open("w");
logFile.writeln("Batch Rename & Export Log – " + new Date());
// 2. Loop through all open documents
for (var i = 0; i < app.documents.length; i++) {
var doc = app.documents[i];
logFile.writeln("\nProcessing document: " + doc.name);
// 3. Rename layers sequentially
for (var l = 0; l < doc.layers.length; l++) {
var layer = doc.layers[l];
var newName = "Layer_" + (l + 1).toString().padStart(2, "0");
layer.name = newName;
logFile.writeln(" Renamed layer " + (l + 1) + ": " + newName);
}
// 4. Export each artboard as PNG
for (var a = 0; a < doc.artboards.length; a++) {
var artboard = doc.artboards[a];
var artboardName = artboard.name || ("Artboard_" + (a + 1));
var pngFile = new File(doc.path + "/" + doc.name.replace(/\\.ai$/, "") + "_" + artboardName + ".png");
var exportOpts = new ExportOptionsPNG24();
exportOpts.antiAliasing = true;
exportOpts.transparency = true;
exportOpts.resolution = 300;
exportOpts.artBoardClipping = true;
doc.exportFile(pngFile, ExportType.PNG24, exportOpts);
logFile.writeln(" Exported PNG: " + pngFile.name);
}
}
logFile.close();
alert("Batch operation complete. Check the log on your desktop.");
**What to Check After Running:**
- Open the log file – every renamed layer and exported PNG should be listed.
- Verify that the PNGs match the artboard content at 300 dpi.
- Open a few layers to confirm the new names.
Trade‑offs and Limitations
- ECMAScript 3 Restrictions: Modern JavaScript features (const, let, arrow functions) are unavailable. Stick to
varand classic functions. - Version Drift: A property like
layer.isBackgroundLayerexisted in CC 2020 but was removed in CC 2023. Always consult the reference for the target release. - Hidden Features: Some Illustrator actions – e.g., the new Vector Studio brushes – are not exposed to ExtendScript. In those cases you must call
app.executeMenuCommand("commandName")or build a UXP plugin. - Performance: Scripts run in the UI thread. For thousands of artboards, consider batching the export in smaller groups or using a background process via UXP.
When to Switch to UXP
Adobe’s UXP platform offers modern JavaScript, async APIs, and a sandboxed environment. If your automation requires the latest UI components or needs to run as a plugin, UXP is the future. However, for quick batch tasks, ExtendScript remains the quickest path because it ships with Illustrator and requires no external dependencies.
Actionable Takeaway
Identify the repetitive vector tasks in your workflow – layer renaming, artboard resizing, asset export – and prototype a small ExtendScript. Test it on a copy of your files, verify the log, and iterate. Once stable, integrate the script into your design pipeline or share it with teammates via a shared folder or version control. The result: a measurable reduction in manual effort and a lower chance of human error.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.