I’m making an ExtendScript script which goes through all the fonts used in an InDesign document and alerts their name. Here is the code
var usedFonts = app.activeDocument.fonts;
var nbUsedFonts = usedFonts.length;
var i;
for (i = 0; i < nbUsedFonts; ++i) {
alert(usedFonts.item(i).name);
}
For certain fonts however, the script crashes (Object is invalid) when I access their name property. The only attribute I can access for all fonts without crashing is the isValid attribute, which allowed me to determine that those fonts for which I couldn’t access the name property all had isValid === false, whereas all fonts for which accesing name didn’t cause a problem had isValid === true.
What surprises me is that if I manually place my cursor in the text where one of the problematic fonts is used, its name appears the the normal font chooser or whatever it’s called.
Why can’t I access the name property for some fonts returned to me by app.activeDocument.fonts?
Note:
Here are some of the problematic fonts:
- Electra LH, Italic
- Electra LH, Bold Small Caps & Oldstyle Figures
- Electra LH, Oldstyle Figures
- Ocean Sans MT, Light OsF
These fonts work without problem:
- Ocean Sans MT, Light Italic OsF
- Ocean Sans MT, Semibold SC
- Ocean Sans MT, Light SC
- Ocean Sans MT, Light
- Electra LH, Small Caps & Oldstyle Figures
- Electra LH, Cursive
- Electra LH, Bold Oldstyle Figures
The problem may come from fonts missing, you may try to check for these first, and see if it solves your problem: