Last active
July 27, 2023 01:59
-
-
Save timothylong/8077fc49790f38cecf6af788f9aa99cf to your computer and use it in GitHub Desktop.
illustrator batch script to expand stroke on SVG files and resave
This file contains 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
// 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