Skip to content

Instantly share code, notes, and snippets.

@timothylong
Last active July 27, 2023 01:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timothylong/8077fc49790f38cecf6af788f9aa99cf to your computer and use it in GitHub Desktop.
Save timothylong/8077fc49790f38cecf6af788f9aa99cf to your computer and use it in GitHub Desktop.
illustrator batch script to expand stroke on SVG files and resave
// Reference: https://forums.adobe.com/thread/2395503
//Change this to your AI files folder (Be sure to end with a /)
var location = "/C/Users/username/Desktop/icon/";
function getFiles() {
var folder = new Folder(location);
if (folder.exists) {
return folder.getFiles("*.svg");
} else {
alert("Unable to find SVG Files Folder");
}
}
function openFiles(files) {
var documents = [];
for (var i = 0; i < files.length; i++) {
var file = files[i];
documents.push(app.open(file));
}
return documents;
}
function saveFile(destination, name, document) {
var folder = new Folder(destination);
if (!folder.exists) folder.create();
var destFile = new File(destination +name);
var options = new ExportOptionsSVG();
document.exportFile(destFile, ExportType.SVG, options);
}
/*
* Run script
*/
openAndExpand();
function openAndExpand() {
try {
var files = getFiles();
if (files.length > 0) {
//Open Each File
var documents = openFiles(files);
if (documents.length > 0) {
//Expand Each File and Save
for (var i = 0; i < documents.length; i++) {
var document = documents[i];
document.activate();
expandFile();
saveFile(location + "/output/", document.name, document);
}
//Close All Documents
for (var i = 0; i < documents.length; i++) {
documents[i].close();
}
}
}
} catch(e) {
alert("Error Processing:");
alert(e);
}
}
function expandFile() {
app.executeMenuCommand("selectall");
app.executeMenuCommand ('Live Outline Stroke');
app.executeMenuCommand ('expandStyle');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment