Quantcast
Channel: Adobe Community: Message List - InDesign Scripting
Viewing all articles
Browse latest Browse all 37788

Re: Specified font need to be changed in all paragraph styles

$
0
0

ok.. this should work for most cases:

 

 

function main(){          var doc=app.activeDocument;          var myDialog= new Window("dialog","Font replacer");          var grp1=myDialog.add("group");          var panel1=grp1.add("panel",undefined,"Find font:");          var panel2=grp1.add("panel",undefined,"Change font:");          var findFonts=doc.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");          var chFonts=app.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");          var myFindDrop=panel1.add("dropdownlist",undefined,findFonts);          var myChDrop=panel2.add("dropdownlist",undefined,chFonts);          myDialog.add("button",undefined,"Ok",{name:"ok"});          myDialog.add("button",undefined,"Cancel",{name:"cancel"});          myFindDrop.selection=myFindDrop.items[0];          myChDrop.selection=myChDrop.items[0];          if (myDialog.show()) {                    var pstyles = doc.allParagraphStyles;                    var cstyles = doc.allCharacterStyles;                    var ffont = myFindDrop.selection.text.replace(/:/g,"\t");                    var tfont = myChDrop.selection.text.replace(/:/g,"\t");                    for (var a = 1; a < pstyles.length; a++) {                              if (pstyles[a].appliedFont.name==ffont) {                                        pstyles[a].appliedFont = tfont;                              }                    };                    for (var i = 1; i < cstyles.length; i++) {                              if ((cstyles[i].appliedFont+'\t'+cstyles[i].fontStyle==ffont)||(cstyles[i].appliedFont.name==ffont)) {                                        cstyles[i].appliedFont = tfont;                              }                    };          }  }app.doScript("main()",undefined,undefined,UndoModes.fastEntireScript,'Global Change Font'); 

 

When i'll have the time i'll probably do a more advanced version, to change font families or just font variants etc.

However, for your example, it won't change the character style "three". I'm curious about how did you defined that style because while in the interface it shows that the applied font is "Minion Pro" and the font style is "Regular", when i get the font Style property from the script it reports as "Roman". Very very wierd.


Viewing all articles
Browse latest Browse all 37788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>