Skip to content

Instantly share code, notes, and snippets.

@chanpory
Forked from rozklad/BatchOutline.js
Last active March 24, 2022 19:33
Show Gist options
  • Save chanpory/3fe741438a1be71ee9187355a9d9ea91 to your computer and use it in GitHub Desktop.
Save chanpory/3fe741438a1be71ee9187355a9d9ea91 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 processFiles(files) {
var documents = [];
for (var i = 0; i < files.length; i++) {
var file = files[i];
var document = app.open(file);
document.activate();
expandFile();
saveFile(outputLocation, document.name, document);
document.close();
}
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();
processFiles(files)
} catch(e) {
alert('Error Processing:');
alert(e);
}
}
function expandFile() {
app.executeMenuCommand('selectall');
app.executeMenuCommand('Live Outline Stroke');
app.executeMenuCommand('expandStyle');
}
// Execute
openAndExpand();
@chanpory
Copy link
Author

Original script created out of memory issues in Illustrator when there are too many files. This version still crashes illustrator after a few hundred SVGs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment