Created
August 5, 2023 17:28
-
-
Save parrotmac/3408c575884758f07b35dd52f69843e7 to your computer and use it in GitHub Desktop.
Illustrator Batch Generate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global app, $ */ | |
var names = [ | |
"Alfa", | |
"Bravo", | |
"Charlie", | |
"Delta", | |
"Echo", | |
"Foxtrot", | |
"Golf", | |
"Hotel", | |
"India", | |
"Juliet", | |
"Kilo", | |
"Lima", | |
"Mike", | |
"November", | |
"Oscar", | |
"Papa", | |
"Quebec", | |
"Romeo", | |
"Sierra", | |
"Tango", | |
"Uniform", | |
"Victor", | |
"Whiskey", | |
"X-ray", | |
"Yankee", | |
"Zulu" | |
]; | |
function getArtboardCount() { | |
return names.length/2; | |
} | |
function getPerArtboard() { | |
return 2; | |
} | |
function getName(index) { | |
if (index > names.length - 1) { | |
return ""; | |
} | |
var n = names[index]; | |
var spaces = 20 - n.length; | |
if (spaces < 0) { | |
spaces = 0; | |
} | |
var s = ""; | |
for (var i = 0; i < spaces; i++) { | |
s += " "; | |
} | |
return n + s; | |
} | |
function getReplacement(index, text) { | |
if (text === "REPLACE_ME") { | |
return getName(index); | |
} | |
return getName(index + 1); | |
} | |
var PER_LINE = 4; | |
function main() { | |
var templateArtboard = null; | |
if (app.documents.length > 0) { | |
var doc = app.activeDocument; | |
var artboards = doc.artboards; | |
for (var i = 0; i < artboards.length; i++) { | |
if (artboards[i].name == "TEMPLATE") { | |
templateArtboard = artboards[i]; | |
doc.selectObjectsOnActiveArtboard(); | |
app.copy(); | |
break; | |
} | |
} | |
if (templateArtboard == null) { | |
alert("No template artboard found"); | |
} | |
for (var j = 0; j < getArtboardCount(); j++) { | |
var x1 = templateArtboard.artboardRect[2] + (800 * ((j % PER_LINE) + 1)); | |
var y1 = templateArtboard.artboardRect[1] - (800 * Math.floor(j / PER_LINE) + 1); | |
var x2 = x1 + templateArtboard.artboardRect[2]; | |
var y2 = templateArtboard.artboardRect[3] - (800 * Math.floor(j / PER_LINE) + 1); | |
var ab = doc.artboards.add([x1, y1, x2, y2]); | |
app.executeMenuCommand("pasteFront"); | |
doc.selectObjectsOnActiveArtboard(); | |
var selectedObjects = app.activeDocument.selection; | |
for (var i = 0; i < selectedObjects.length; i++) { | |
if (selectedObjects[i].typename === "TextFrame") { | |
var txtContent = selectedObjects[i].textRange.contents; | |
if (txtContent === "REPLACE_ME" || txtContent === "REPLACE_ME_1") { | |
selectedObjects[i].textRange.contents = getReplacement(j * getPerArtboard(), txtContent); | |
} | |
} | |
selectedObjects[i].selected = false; | |
} | |
} | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment