Skip to content

Instantly share code, notes, and snippets.

@Wolfr Wolfr/save-batch.js
Created Oct 18, 2018

Embed
What would you like to do?
Convert SVG icons that are stroke-based to expanded shapes in Illustrator. Use the Scripts functionality to run this script.
// Change this to your AI files folder (Be sure to end with a /)
var location = "/Users/Downloads/my-file/";
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
You can’t perform that action at this time.