Created
May 23, 2012 22:43
-
-
Save marcus-downing/2778294 to your computer and use it in GitHub Desktop.
List the fonts used in all the Illustrator files in a folder
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
/* | |
List the fonts | |
This shows you all the fonts used in all the Illustrator files in a folder, | |
even if the fonts aren't installed on your system. | |
You can then replace them with this script: https://gist.github.com/2778305 | |
*/ | |
function getAllFiles(folder) { | |
var fileList = []; | |
function recurse (folder) { | |
var files = folder.getFiles("*.ai"); | |
for (var i = 0; i < files.length; i++) | |
fileList.push(files[i]); | |
var folders = folder.getFiles(); | |
var len = folders.length; | |
for (var i = 0; i < len; i++) { | |
if (folders[i] instanceof Folder) { | |
recurse(folders[i]); | |
} | |
} | |
} | |
if (folder != null) | |
recurse(folder); | |
return fileList; | |
} | |
// collect the fonts | |
var sourceFolder = Folder.myDocuments.selectDlg( 'Select the folder with Illustrator files in which you want to replace fonts'); | |
var files = getAllFiles(sourceFolder); | |
var fonts = []; | |
for ( var i = 0; i < files.length; i++ ) { | |
var doc = app.open(files[i]); | |
var frames = doc.textFrames; | |
for ( var j = 0; j < frames.length; j++ ) { | |
var ranges = frames[j].textRanges; | |
range_loop: | |
for ( var k = 0; k < ranges.length; k++ ) { | |
var range = ranges[k]; | |
var family = range.characterAttributes.textFont.family; | |
var style = range.characterAttributes.textFont.style; | |
var entry = { 'family': family, 'style': style }; | |
var elen = fonts.length; | |
for (var e = 0; e < elen; e++) { | |
var dentry = fonts[e]; | |
if (entry.family == dentry.family && entry.style == dentry.style) | |
continue range_loop; | |
} | |
fonts.push(entry); | |
} | |
} | |
doc.close(); | |
} | |
// Adapted from the Illustrator Scripting Reference CS5 page 216 | |
// Creates a new A3 sized document and display a list of available fonts until the document is full. | |
var edgeSpacing = 10; | |
var columnSpacing = 230; | |
var docPreset = new DocumentPreset; | |
docPreset.width = 1191.0; | |
docPreset.height = 842.0 | |
var doc = documents.addDocument(DocumentColorSpace.CMYK, docPreset); | |
var labelRef = doc.textFrames.add(); | |
if (labelRef) { | |
labelRef.textRange.characterAttributes.size = 10; | |
labelRef.contents = "Fonts used in "+sourceFolder.fullName; | |
labelRef.top = doc.height - edgeSpacing; | |
labelRef.left = edgeSpacing; | |
} | |
var fontName = ""; | |
var x = edgeSpacing; | |
var y = (doc.height - edgeSpacing - 20); | |
var count = fonts.length; | |
for (var i = 0; i < count; i++) { | |
//sFontName = ; | |
//sFontName += " / "; | |
fontName = fonts[i].family + " / " + fonts[i].style; | |
var textRef = doc.textFrames.add(); | |
textRef.textRange.characterAttributes.size = 10; | |
textRef.contents = fontName; | |
textRef.top = y; | |
textRef.left = x; | |
// check wether the text frame will go off the edge of the document | |
if ((x + textRef.width)> doc.width){ | |
textRef.remove(); | |
iCount = i; | |
break; | |
} else{ | |
// display text frame | |
if( (y-=(textRef.height)) <= 20 ) { | |
y = (doc.height - edgeSpacing - 20); | |
x += columnSpacing; | |
} | |
} | |
} | |
redraw(); |
You may have more success with this version of the script:
It relies on the Tools.jsxinc
and underscore.js
files, so download those together.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
The version of JavaScript (or ExtendScript) used by Adobe Illustrator is very different from the dialect you'll find anywhere else. It needs to be run directly inside Illustrator to get the APIs it needs.
That should then come up with some dialog boxes prompting you to pick a folder.