-
-
Save chanpory/3fe741438a1be71ee9187355a9d9ea91 to your computer and use it in GitHub Desktop.
Batch Outline stroke all SVG files in folder using Adobe Illustrator
This file contains hidden or 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
/** | |
* 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.