Skip to content

Instantly share code, notes, and snippets.

@rozklad
Created August 4, 2019 08:57
Show Gist options
  • Save rozklad/9eda48001e9c625b569a7d09083e2e8e to your computer and use it in GitHub Desktop.
Save rozklad/9eda48001e9c625b569a7d09083e2e8e to your computer and use it in GitHub Desktop.
Batch Outline stroke all SVG files in folder using Adobe Illustrator
/**
* Batch Outline stroke all SVG files in folder using Adobe Illustrator.
*
* Usage:
* 1) Adjust location and outputLocation variables and save as BatchOutline.js anywhere
* 2) File > Scripts > Other script (CMD + F12) and open BatchOutline.js
*
* @credits https://forums.adobe.com/thread/2395503
* @version 1.1
*/
var location = '/path/to/svg/folder';
var outputLocation = '/path/to/svg/folder/output';
function getFiles() {
var folder = new Folder(location);
if (folder.exists) {
return folder.getFiles('*.svg');
} else {
alert('Folder ' + folder + ' does not exist');
}
}
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);
}
function openAndExpand() {
try {
var files = getFiles();
if (files.length > 0) {
var documents = openFiles(files);
if (documents.length > 0) {
for (var i = 0; i < documents.length; i++) {
var document = documents[i];
document.activate();
expandFile();
saveFile(outputLocation, document.name, document);
}
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');
}
// Execute
openAndExpand();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment