Copy link to clipboard
Copied
Hi,
Preface: I have a very rough understanding of javascript, so bear with me if my questions are very simple.
I have a bunch of documents I need to edit. For all of them, I know I need to change a font (with two different syles), and I need to do a colour replacement.
Here is some code I patched together:
for (var i = app.documents.length-1; i >= 0; i--) {
var doc = app.documents;
fontChange();
function fontChange(){
step1();
}
function step1(){
//Tuffy Regular > Roboto Regular
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.appliedFont = "Tuffy";
app.findTextPreferences.fontStyle = "Regular";
app.changeTextPreferences.appliedFont = "Roboto";
app.changeTextPreferences.fontStyle = "Regular";
app.activeDocument.pageItems.everyItem().locked = false;
app.activeDocument.stories.everyItem().changeText();
app.findChangeTextOptions.includeMasterPages = true;
}
fontChangeTwo();
function fontChangeTwo(){
step2();
}
function step2(){
//Tuffy Bold > Roboto Bold
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.appliedFont = "Tuffy";
app.findTextPreferences.fontStyle = "Bold";
app.changeTextPreferences.appliedFont = "Roboto";
app.changeTextPreferences.fontStyle = "Bold";
app.activeDocument.pageItems.everyItem().locked = false;
app.activeDocument.stories.everyItem().changeText();
app.findChangeTextOptions.includeMasterPages = true;
}
}
Problem 1) I thought the first two lines would allow me to run this in all my documents but it doesn't work.
Problem 2) For some reason, my InDesign refuses to recognise Roboto when I run the script. It replaces the font with "Roboto (otf)" and highlights the text in red. It works fine with other fonts. If I manually replace the text in red with "Roboto", it works fine.
I've had issues with Roboto for a while in InDesign, the only way I found to have it work is to NOT activate it on Adobe fonts and have it installed on my machine instead.
Problem 3) The easiest one, I don't know how to do a colour replacement. I need to replace Adobe's pure black with another colour from my palette.
I would be super grateful if anyone could help with any of these problems.
Thanks in advance.
You waver between a number of different approaches. I you want to iterate through the open documents and use app.activeDocument, you must activate (i.e.bring to the front) each document in turn. But there's no need for that (and it's slow bussiness). Instead you can talk to documents without activating them, see your amended script. below.
Some other comments: resetting the preferences is needed only once, you do that before the loop because doing it inside the loop is a waste of time. And to
...I can see that manually changing those fonts isn't really an option. Two suggestions. The best solution would be to get the font that your customer uses. It's likely that their font, though it may have the ame name, has a different version number. InDesign is really as finicky as that. Secondly, if you can't get that font, ask Kasyan to add to his script a line so that a paragraph style's font is changed only if it matches a defined font. It's just a small addition.
All that said, Kasyan'r scr
...Copy link to clipboard
Copied
You waver between a number of different approaches. I you want to iterate through the open documents and use app.activeDocument, you must activate (i.e.bring to the front) each document in turn. But there's no need for that (and it's slow bussiness). Instead you can talk to documents without activating them, see your amended script. below.
Some other comments: resetting the preferences is needed only once, you do that before the loop because doing it inside the loop is a waste of time. And to make a change in a document, there's no need to address its stories: simply target the document itself.
Hope this helps.
Peter
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
for (var i = app.documents.length-1; i >= 0; i--) {
app.documents[i].pageItems.everyItem().locked = false;
step1 (app.documents[i]);
step2 (app.documents[i]);
}
function step1 (doc) {
//Tuffy Regular > Roboto Regular
app.findTextPreferences.appliedFont = "Tuffy";
app.findTextPreferences.fontStyle = "Regular";
app.changeTextPreferences.appliedFont = "Roboto";
app.changeTextPreferences.fontStyle = "Regular";
doc.changeText();
}
function step2 (doc) {
//Tuffy Bold > Roboto Bold
app.findTextPreferences.appliedFont = "Tuffy";
app.findTextPreferences.fontStyle = "Bold";
app.changeTextPreferences.appliedFont = "Roboto";
app.changeTextPreferences.fontStyle = "Bold";
doc.changeText();
}
Copy link to clipboard
Copied
And there is a version that doesn't use a loop:
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.documents.everyItem().pageItems.everyItem().locked = false;
app.findTextPreferences.appliedFont = "Tuffy\tRegular";
app.changeTextPreferences.appliedFont = "Roboto\tRegular";
app.documents.everyItem().changeText();
app.findTextPreferences.appliedFont = "Tuffy\tBold";
app.changeTextPreferences.appliedFont = "Roboto\tBold";
app.documents.everyItem().changeText();
Copy link to clipboard
Copied
Thank you Peter, it works perfectly and it even solved my font problem! I'll do some research about changing font colours another time, I'm sure I can figure it out 🙂
Copy link to clipboard
Copied
It looks like I can't quite figure out how to change the colour everywhere in my document...
I added to the code to replace font colours:
app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.documents.everyItem().pageItems.everyItem().locked = false;
app.findTextPreferences.appliedFont = "Tuffy\tRegular";
app.changeTextPreferences.appliedFont = "Roboto\tRegular";
app.documents.everyItem().changeText();
app.findTextPreferences.appliedFont = "Tuffy\tBold";
app.changeTextPreferences.appliedFont = "Roboto\tBold";
app.documents.everyItem().changeText();
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.strokeColor = "Black";
app.changeTextPreferences.strokeColor = "[other colour]";
app.documents.everyItem().changeText();
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.fillColor = "Black";
app.changeTextPreferences.fillColor = "[other colour]";
app.documents.everyItem().changeText();
This works perfectly. However, I'd like to also replace pure black from shapes and table cells. I tried "
Copy link to clipboard
Copied
For cells you do something different because they're not objects (not objects that you can search anyway). Do something like this:
app.documents[0].tables.everyItem().cells.everyItem().fillColor = 'some fill';
Copy link to clipboard
Copied
Hey Peter,
This script just seems to cycle through and change the preferences, but doesn't replace any fonts in the document.
I'm going mad trying to get this feature to work in a script!
Copy link to clipboard
Copied
There are various versions in this thread. Please show the version that you use.
Copy link to clipboard
Copied
I tried both of your scripts posted here and neither is changing any fonts for me.
Thanks for replying 🙂
Copy link to clipboard
Copied
Are the font and style names spelled correctly?
The posted scripts change only local overrides, not the fonts in paragraph and/or character styles.
Maybe post (part of) your document. It's a simple script, it's not clear what goes wrong.
Copy link to clipboard
Copied
I will tomorrow, I'm away from work for now.
Copy link to clipboard
Copied
I appreciate your time, thanks.
I attach the document below. I'm trying to replace the fiont "Merriwaether (OTF)" with "Merriweather".
The script you provided seems to run OK, and cycles the properties through the Find-Change dialog box, but no fonts are changed in the document.
It's really frustrating, as this should be a built-in feature of the app really.
Copy link to clipboard
Copied
Ah, that one -- the dreaded (OTF) in the font's name. (TT) in the fiont's name is just as bad. That the script doesn't work on fonts with (OTF) or (TT) in their name is caused by an InDesign bug. You can see that as follows: run the script, then open the Find/Change window. You'll see that the font and style names appear correctly in the panels:
Now click in the Find Format panel, then select the Basic Character Format tab. You'll see theat the font name isn't there: that's the problem.
It's in fact a scripting bug, for if you enter the font and style names in the window manually, the replacement works fine. But using the Find/replace Font window is quicker for this type of font.
The problems with (OTF) and (TT) appearing in font names are complex. Try to avoid them as much as possible by making sure that you have the same fonts as those that the other person used. Identical font names aren't good enough: the font version numbers must match as well.
Sorry I can't be of more help.
Copy link to clipboard
Copied
The problem is, I get hundreds of files to typeset and the source files have this (OTF) font applied, but the customer asks for the non-(OTF) version in the returned files.
Every book I get I have to trudge through and change all the fonts.
I have also tried the Change fonts CSV script from Kasyan Servetsky.
This one replaces the (OTF) with the normal font but then replaces all the other fonts in the book with Merriweather as well!
I'm using the following in the .csv file:
Merriweather (OTF)\tRegular;Merriweather\tRegular
Merriweather (OTF)\tItalic;Merriweather\tItalic
Merriweather (OTF)\tBold;Merriweather\tBold
Copy link to clipboard
Copied
I can see that manually changing those fonts isn't really an option. Two suggestions. The best solution would be to get the font that your customer uses. It's likely that their font, though it may have the ame name, has a different version number. InDesign is really as finicky as that. Secondly, if you can't get that font, ask Kasyan to add to his script a line so that a paragraph style's font is changed only if it matches a defined font. It's just a small addition.
All that said, Kasyan'r script doesn't work for me: it goes through the document, changes the font, but without effect. I had/have the same problem with a script similar to Kasyan's that I did a while ago (https://creativepro.com/files/kahrel/indesign/substitute_fonts.html).
Anyway, get in touch with Kasyan and see what he can do for you.
Copy link to clipboard
Copied
Thanks Peter 😃