Created
May 23, 2012 22:45
-
-
Save marcus-downing/2778305 to your computer and use it in GitHub Desktop.
Replace fonts 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
/* | |
Replace fonts in all the Illustrator files in a folder | |
Edit the array at the top to your own substitutions | |
Find the font names to replace using: https://gist.github.com/2778294 | |
*/ | |
// fonts to replace | |
var substitutions = [ | |
['BellGothic BT', 'Bold', 'Roboto', 'Condensed'], | |
['BellGothic Blk BT', 'Black', 'Roboto', 'Bold Condensed'], | |
]; | |
// turn the substitutions into real fonts | |
var subsRight = []; | |
var fontCount = textFonts.length; | |
var subsCount = substitutions.length; | |
for (var i = 0; i < fontCount; i++) { | |
var font = textFonts[i]; | |
for (var j = 0; j < subsCount; j++) { | |
if (substitutions[j][2] == font.family && substitutions[j][3] == font.style) { | |
subsRight[j] = font; | |
} | |
} | |
} | |
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 && folder instanceof Folder) | |
recurse(folder); | |
return fileList; | |
} | |
var sourceFolder = Folder.myDocuments.selectDlg( 'Select the folder with Illustrator files in which you want to replace fonts'); | |
var files = getAllFiles(sourceFolder); | |
for ( var i = 0; i < files.length; i++ ) { | |
var file = files[i]; | |
var doc = app.open(file); | |
// replace the font | |
var frames = doc.textFrames; | |
for ( var j = 0; j < frames.length; j++ ) { | |
var ranges = frames[j].textRanges; | |
for ( var k = 0; k < ranges.length; k++ ) { | |
var range = ranges[k]; | |
for (var f = 0; f < subsCount; f++) { | |
if (range.characterAttributes.textFont.family == substitutions[f][0] | |
&& range.characterAttributes.textFont.style == substitutions[f][1]) { | |
range.characterAttributes.textFont = subsRight[f]; | |
} | |
} | |
} | |
} | |
redraw(); | |
doc.save(); | |
doc.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Marcus, I was able to make both works in CC2020. This one an the other you pointed me to.
I don’t know if the is my missing font, but it will not replace it.
The script to get his name when missing give me:
It’s name is «SolidEdgeISOCE» with no style.
In character panel when missing:
It’s name is «SolidEdgeISOCE» with Style «Normal»
In character panel and with script when available:
It’s name is «Solid Edge ISO CE» with Style «Regular».
Both script with any combinaison of name/style can’t find/replace that missing font.