Skip to content

Instantly share code, notes, and snippets.

@marcus-downing
Created May 23, 2012 22:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcus-downing/2778305 to your computer and use it in GitHub Desktop.
Save marcus-downing/2778305 to your computer and use it in GitHub Desktop.
Replace fonts in all the Illustrator files in a folder
/*
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();
}
@jctremblay65
Copy link

Hello Marcus,

Do you know if this script is still compatible with Ai CC 2020?

@jctremblay65
Copy link

I always get this error.
Capture d’écran 2020-09-12 à 13 54 09

@marcus-downing
Copy link
Author

marcus-downing commented Sep 13, 2020

Hi,

A more recent copy of this script can be found here:
https://github.com/dyslexic-charactersheets/scripts/blob/master/Replace%20fonts%20in%20AI%20from%20CSV.jsx. You may find it better.

I haven't tested either of them with Adobe CC. The last version I tested it on was Illustrator CS6.

@jctremblay65
Copy link

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.

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