1 2 Previous Next 45 Replies Latest reply on Sep 21, 2016 11:16 PM by Oriup

    Specified font need to be changed in all paragraph styles

    Chinnadk Level 4

      Hi All,

       

      Is there any option to change a font which is used in many paragarph styles to some other font.

       

      Thanks in advance,

        • 1. Re: Specified font need to be changed in all paragraph styles
          Vamitul Level 4

          perhaps soem nore information is needed.

          Have you tried Find Font? ("Type" menu-> "Find font")?

          • 2. Re: Specified font need to be changed in all paragraph styles
            Chinnadk Level 4

            Thanks for your replay Vamitul!

             

            Yes I tried ("Type" menu-> "Find font") but it only works on when the paragraph styles applied to any texts in the document but i need to change the font of the paragarphstyles when it is not applied to any texts

             

            Say for example a and b are paragraph styles applied "Times" font these styles applied font should be changed to some other font.

            • 3. Re: Specified font need to be changed in all paragraph styles
              Sajeev Sridharan Level 4

              Hope this will help you..

               

              var myDoc=app.activeDocument;

              var allStyles = new Array('parastyle1', 'parastyle2', 'parastyle3');//style name here

              for (a=0; a<allStyles.length; a++)

              {

                  var testStyle = myDoc.paragraphStyles.itemByName(allStyles[a]);

                  testStyle.appliedFont = "Minion";//font name here

              }

               

               

              Vandy

              • 4. Re: Specified font need to be changed in all paragraph styles
                Chinnadk Level 4

                Thanks for your reply Vandy,

                 

                Here is my code. Minion Pro font need to be changed as Avenir LT Std in all the paragraph styles.

                 

                var myDoc=app.activeDocument;

                var pstyles = myDoc.paragraphStyles.everyItem().name;

                var allStyles = new Array(pstyles);//style name here

                var minion = myDoc.fonts.item("Minion Pro");

                var Avenir = myDoc.fonts.item("Avenir LT Std");

                for (a=0; a<allStyles.length; a++)

                {

                    if (allStyles[a]==minion){

                         var testStyle = allStyles[a];

                         testStyle.appliedFont = Avenir;//font name here

                    }

                }

                • 5. Re: Specified font need to be changed in all paragraph styles
                  Vamitul Level 4

                  Try this:

                   

                  var myDoc=app.activeDocument;
                  var pstyles = myDoc.allParagraphStyles;
                  for (var a=1; a<allStyles.length; a++)
                  {
                      if (pstyles[a].appliedFont.name.match(/minion/i){
                           pstyles[a].appliedFont="Avenir LT Std";
                         }
                  }
                  

                   

                   

                  explanations:

                   

                  allParagraphsStyles gets an array of every paragraph style in the doc, regardless of the group it might be in. myDoc.paragraphStyles.everyItem() gets a collection of all the paragraphs styles outside groups.

                   

                  running the array of paragraph styles for 1, not 0, because the first one is "no paragraph style" and it's read only. trying to change it will cause a error.

                   

                  using a regex to match the name of the font because appliedFont.name returns a string like this: font_name {tab character} font_style  eg: "Minion Pro\tSemibold Subhead"

                   

                  hope it helps.

                  • 6. Re: Specified font need to be changed in all paragraph styles
                    Chinnadk Level 4

                    Thank you so much vamitul!

                     

                    it works fine for me.

                    • 7. Re: Specified font need to be changed in all paragraph styles
                      Chinnadk Level 4

                      Hi Vamitul,

                       

                      The same is not working with Character styles. Definitely I made a mistake but i unable to find it. Please help...

                       

                      var dlg = app.dialogs.add({name:"Changing Fonts Globally in all Styles"});

                      var dlc1 = dlg.dialogColumns.add();

                      var dlr =dlc1.borderPanels.add();

                      dlr.staticTexts.add({staticLabel:"From font"});

                      var fromfont = dlr.textEditboxes.add({minWidth:100});

                      dlr.staticTexts.add({staticLabel:"To font"});

                      var tofont = dlr.textEditboxes.add({minWidth:100});

                      dlg.show();

                      var myDoc=app.activeDocument;

                      var pstyles = myDoc.allParagraphStyles;

                      var cstyles = myDoc.allCharacterStyles;

                      var ffont = fromfont.editContents;

                      var tfont = tofont.editContents;

                      for (var a=1; a<pstyles.length; a++)

                      {

                          if (pstyles[a].appliedFont.name.match(ffont)){

                               pstyles[a].appliedFont=tfont;

                             }

                      };

                      for (var i=1; i<cstyles.length; i++)

                      {

                          if (cstyles[i].appliedStyle.name.match(ffont)){

                               cstyles[i].appliedStyle=tfont;

                             }

                      };

                       

                      Thanks in advance,

                      • 8. Re: Specified font need to be changed in all paragraph styles
                        SureshRaji Level 2

                        Hi Chinna,

                         

                        Try this

                         

                        if (cstyles[i].fontStyle.match(ffont)){

                                 cstyles[i].fontStyle=tfont;

                               }

                        • 9. Re: Specified font need to be changed in all paragraph styles
                          Vamitul Level 4

                          try this (sorry about the ugly interface):

                          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.name==ffont) {
                                                                  cstyles[i].appliedFont = tfont;
                                                        }
                                              };
                                    }
                          
                          
                          }app.doScript("main()",undefined,undefined,UndoModes.fastEntireScript,'Global Change Font');
                          
                          • 10. Re: Specified font need to be changed in all paragraph styles
                            Chinnadk Level 4

                            Thanks Vamitul,

                             

                            I will try this.

                            • 11. Re: Specified font need to be changed in all paragraph styles
                              Chinnadk Level 4

                              Hi Vamitul,

                               

                              Thanks for your script it is only working fine on the paragraph styles but it is not working on the character styles.

                              • 12. Re: Specified font need to be changed in all paragraph styles
                                Vamitul Level 4

                                strange, it works on my test documents. can you send me a sample document to see why/what doesn't work?

                                • 13. Re: Specified font need to be changed in all paragraph styles
                                  Chinnadk Level 4

                                  Hi Vamitul,

                                   

                                  How do i send document i dont find any option here

                                   

                                  Note: im using CS5.5

                                  • 14. Re: Specified font need to be changed in all paragraph styles
                                    SureshRaji Level 2

                                    Hi Chinna

                                     

                                    Ignore this if it is wrong.

                                     

                                    "cstyles[i].appliedFont.name==ffont" will return the font family("Minion Pro") and font style("Regular").

                                     

                                    If font family of your character style is not specifid (only font style is specified in the style) then above condition will fail.

                                     

                                    If my suggestion is wrong, I apologize for that.

                                    • 15. Re: Specified font need to be changed in all paragraph styles
                                      Vamitul Level 4

                                      Hi Suresh (hope i don't say something wrong/wierd if i short your name like that).

                                      if the font family is not defined in the charater style, cstyles[i].appliedFont.name will return "undefined". and since undefined does not equal the font name, the script will just ignore the char style and move on.

                                       

                                      Chinna, if you click on my profile pic you shoud get my e-mail address (vamitulATgmailDOTcom----)

                                      • 16. Re: Specified font need to be changed in all paragraph styles
                                        SureshRaji Level 2

                                        Hi Vamitul

                                         

                                         

                                        Thanks for your reply.

                                         

                                         

                                        Regards

                                        Suresh

                                        • 18. Re: Specified font need to be changed in all paragraph styles
                                          Vamitul Level 4

                                          well.. i found the problem. a wierd one even. apparently characterStyle.appliedFont does not return a font, but a string. will try to fix it and get back to you later today, i hope.

                                          • 20. Re: Specified font need to be changed in all paragraph styles
                                            Vamitul Level 4

                                            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.

                                            1 person found this helpful
                                            • 22. Re: Specified font need to be changed in all paragraph styles
                                              Chinnadk Level 4

                                              Hi Vamitul,

                                               

                                              I found the solution. Here is my script.

                                               

                                                  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 docfonts=doc.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");

                                                 

                                                  var appfonts=app.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");

                                                 

                                                  var arrayofdocfont=panel1.add("dropdownlist",undefined,docfonts);

                                                  var arrayofappfont=panel2.add("dropdownlist",undefined,appfonts);

                                                  myDialog.add("button",undefined,"Ok",{name:"ok"});

                                                  var cancel = myDialog.add("button",undefined,"Cancel",{name:"cancel"});

                                                  cancel.onClick = function (){

                                                          myDialog.close ();

                                                      }

                                                  arrayofdocfont.selection=arrayofdocfont.items[0];

                                                  arrayofappfont.selection=arrayofappfont.items[0];

                                               

                                               

                                                  if(myDialog.show()) {

                                                      var pstyles = doc.allParagraphStyles;

                                                      var cstyles = doc.allCharacterStyles;

                                                      var pstylefont = arrayofdocfont.selection.text.replace(/:/g,"\t").toString();

                                                     

                                                      var cstylefont = arrayofdocfont.selection.text.replace(/:.*/g,"");

                                               

                                                      var tfont = arrayofappfont.selection.text.replace(/:/g,"\t");

                                                      for (var a = 1; a < pstyles.length; a++) {

                                                          if (pstyles[a].appliedFont.name==pstylefont) {

                                                              pstyles[a].appliedFont = tfont;

                                                          }

                                                      };

                                                      for (var i = 1; i < cstyles.length; i++) {

                                                         if (cstyles[i].appliedFont ==cstylefont) {

                                                          cstyles[i].appliedFont =tfont;

                                                          }

                                                       

                                                      }

                                                  }

                                               

                                              Regards,

                                              Chinna

                                              • 23. Re: Specified font need to be changed in all paragraph styles
                                                Suzan.V Level 1

                                                Hello Vamitul.

                                                i hope you are doing well

                                                 

                                                kindly please can you edit your code to be applied on all  opened documents

                                                 

                                                 

                                                Thanks a lot

                                                • 27. Re: Specified font need to be changed in all paragraph styles
                                                  Vamitul Level 4

                                                  Why? Why not?

                                                  Because I don't want to should suffice, but for a longer explanation:
                                                  Because I'm not here to provide ready-made scripts, to order.
                                                  Because it's a trivial change to be made by anyone who has the least bit of interest in scripting and it is here on this forum to learn more, not just ask for freebies.

                                                  Because I don't have the time, the energy or the passion to help anyone who is not interested.

                                                  • 28. Re: Specified font need to be changed in all paragraph styles
                                                    Suzan.V Level 1

                                                    well then i think you can just say that you don't have time and i won't be shocked from your response like previous one,

                                                     

                                                    by the way i'm so interested and i did many tries on your code to be just like i requested (politely)  but i failed, i'm already add more features to it like multiple find/change processes but about that point i didn't get lucky ..

                                                     

                                                    thanks anyway as i said

                                                    • 29. Re: Specified font need to be changed in all paragraph styles
                                                      tpk1982 Level 4

                                                      Suzan,

                                                       

                                                      Applying to all open document is not a big task.. take the documents length and use for loop to acheive...

                                                      • 30. Re: Specified font need to be changed in all paragraph styles
                                                        Suzan.V Level 1

                                                        tpk1982

                                                         

                                                        i think that is my bad luck

                                                        how come i have gone further with this code and i can't do that bloody small thing :/ :/

                                                         

                                                        thanks for your hint, but still failed.

                                                         

                                                         

                                                        i succeeded to add multiple find / replace processes and panels but failed with this LOL

                                                        • 31. Re: Specified font need to be changed in all paragraph styles
                                                          tpk1982 Level 4

                                                          Which code you need to apply to all documents? Is it the below one?

                                                           

                                                          var myDoc=app.activeDocument; 

                                                          var pstyles = myDoc.allParagraphStyles; 

                                                          for (var a=1; a<allStyles.length; a++) 

                                                              if (pstyles[a].appliedFont.name.match(/minion/i){ 

                                                                   pstyles[a].appliedFont="Avenir LT Std"; 

                                                                 } 

                                                           

                                                           

                                                          or some other by Chinna's one?

                                                          • 32. Re: Specified font need to be changed in all paragraph styles
                                                            Suzan.V Level 1

                                                            actually that code after i did editing to be a multiple find/replace

                                                             

                                                             

                                                            function main(){ 

                                                                      var doc=app.activeDocument; 

                                                                     

                                                                      var myDialog= new Window("dialog","Font Find/Change"); 

                                                             

                                                             

                                                                      var grp1=myDialog.add("group"); 

                                                                      var panel1=grp1.add("panel",undefined,"Find Font:"); 

                                                                      var panel2=grp1.add("panel",undefined,"Change Font:");

                                                                     

                                                                     

                                                                      var findFonts1=doc.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r"); 

                                                                      var chFonts1=app.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r"); 

                                                                      var myFindDrop1=panel1.add("dropdownlist",undefined,findFonts1); 

                                                                      var myChDrop1=panel2.add("dropdownlist",undefined,chFonts1); 

                                                                     

                                                                     

                                                                      var grp2=myDialog.add("group"); 

                                                                      var panel3=grp2.add("panel",undefined,"Find Font:"); 

                                                                      var panel4=grp2.add("panel",undefined,"Change Font:");         

                                                                     

                                                                      var findFonts2=doc.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r"); 

                                                                      var chFonts2=app.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");                   

                                                                      var myFindDrop2=panel3.add("dropdownlist",undefined,findFonts2); 

                                                                      var myChDrop2=panel4.add("dropdownlist",undefined,chFonts2);          

                                                                     

                                                                       var grp3=myDialog.add("group"); 

                                                                      var panel5=grp3.add("panel",undefined,"Find Font:"); 

                                                                      var panel6=grp3.add("panel",undefined,"Change Font:");         

                                                                     

                                                                      var findFonts3=doc.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r"); 

                                                                      var chFonts3=app.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");                   

                                                                      var myFindDrop3=panel5.add("dropdownlist",undefined,findFonts3); 

                                                                      var myChDrop3=panel6.add("dropdownlist",undefined,chFonts3);             

                                                                     

                                                             

                                                             

                                                                       var grp4=myDialog.add("group"); 

                                                                      var panel7=grp4.add("panel",undefined,"Find Font:"); 

                                                                      var panel8=grp4.add("panel",undefined,"Change Font:");         

                                                                     

                                                                      var findFonts4=doc.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r"); 

                                                                      var chFonts4=app.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");                   

                                                                      var myFindDrop4=panel7.add("dropdownlist",undefined,findFonts4); 

                                                                      var myChDrop4=panel8.add("dropdownlist",undefined,chFonts4);     

                                                                     

                                                                        var grp5=myDialog.add("group"); 

                                                                      var panel9=grp5.add("panel",undefined,"Find Font:"); 

                                                                      var panel10=grp5.add("panel",undefined,"Change Font:");         

                                                                     

                                                                      var findFonts5=doc.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r"); 

                                                                      var chFonts5=app.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");                   

                                                                      var myFindDrop5=panel9.add("dropdownlist",undefined,findFonts5); 

                                                                      var myChDrop5=panel10.add("dropdownlist",undefined,chFonts5);             

                                                                     

                                                                       var grp6=myDialog.add("group"); 

                                                                      var panel11=grp6.add("panel",undefined,"Find Font:"); 

                                                                      var panel12=grp6.add("panel",undefined,"Change Font:");         

                                                                     

                                                                      var findFonts6=doc.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r"); 

                                                                      var chFonts6=app.fonts.everyItem().name.join("\r").replace(/\t/g,":").split("\r");                   

                                                                      var myFindDrop6=panel11.add("dropdownlist",undefined,findFonts6); 

                                                                      var myChDrop6=panel12.add("dropdownlist",undefined,chFonts6);               

                                                                     

                                                                     

                                                                     

                                                                     

                                                                     

                                                                     

                                                                      myDialog.add("button",undefined,"Ok",{name:"ok"}); 

                                                                      myDialog.add("button",undefined,"Cancel",{name:"cancel"}); 

                                                                     

                                                                     

                                                                     

                                                                     

                                                                      myFindDrop1.selection=myFindDrop1.items[0]; 

                                                                      myChDrop1.selection=myChDrop1.items[0]; 

                                                                      myFindDrop2.selection=myFindDrop2.items[0]; 

                                                                      myChDrop2.selection=myChDrop2.items[0]; 

                                                                       myFindDrop3.selection=myFindDrop3.items[0]; 

                                                                      myChDrop3.selection=myChDrop3.items[0];

                                                                       myFindDrop4.selection=myFindDrop4.items[0]; 

                                                                      myChDrop4.selection=myChDrop4.items[0];

                                                                       myFindDrop5.selection=myFindDrop5.items[0]; 

                                                                      myChDrop5.selection=myChDrop5.items[0];          

                                                                       myFindDrop6.selection=myFindDrop6.items[0]; 

                                                                      myChDrop6.selection=myChDrop6.items[0];          

                                                                     

                                                                     

                                                                     

                                                                     

                                                                      if (myDialog.show()) { 

                                                                                var pstyles = doc.allParagraphStyles; 

                                                                                var cstyles = doc.allCharacterStyles; 

                                                                                var ffont = myFindDrop2.selection.text.replace(/:/g,"\t"); 

                                                                                var tfont = myChDrop2.selection.text.replace(/:/g,"\t"); 

                                                                                for (var a = 1; a < pstyles.length; a++) { 

                                                                                          if (pstyles[a].appliedFont.name==ffont) { 

                                                                                                    pstyles[a].appliedFont = tfont; 

                                                                                                   

                                                                                var pstyles = doc.allParagraphStyles; 

                                                                                var cstyles = doc.allCharacterStyles; 

                                                                                var ffont = myFindDrop1.selection.text.replace(/:/g,"\t"); 

                                                                                var tfont = myChDrop1.selection.text.replace(/:/g,"\t"); 

                                                                                for (var a = 1; a < pstyles.length; a++) { 

                                                                                          if (pstyles[a].appliedFont.name==ffont) { 

                                                                                                    pstyles[a].appliedFont = tfont; 

                                                                                                   

                                                                                 var pstyles = doc.allParagraphStyles; 

                                                                                var cstyles = doc.allCharacterStyles; 

                                                                                var ffont = myFindDrop3.selection.text.replace(/:/g,"\t"); 

                                                                                var tfont = myChDrop3.selection.text.replace(/:/g,"\t"); 

                                                                                for (var a = 1; a < pstyles.length; a++) { 

                                                                                          if (pstyles[a].appliedFont.name==ffont) { 

                                                                                                    pstyles[a].appliedFont = tfont; 

                                                                                              

                                                                                  var pstyles = doc.allParagraphStyles; 

                                                                                var cstyles = doc.allCharacterStyles; 

                                                                                var ffont = myFindDrop4.selection.text.replace(/:/g,"\t"); 

                                                                                var tfont = myChDrop4.selection.text.replace(/:/g,"\t"); 

                                                                                for (var a = 1; a < pstyles.length; a++) { 

                                                                                          if (pstyles[a].appliedFont.name==ffont) { 

                                                                                                    pstyles[a].appliedFont = tfont;                                   

                                                                                                   

                                                                                   var pstyles = doc.allParagraphStyles; 

                                                                                var cstyles = doc.allCharacterStyles; 

                                                                                var ffont = myFindDrop5.selection.text.replace(/:/g,"\t"); 

                                                                                var tfont = myChDrop5.selection.text.replace(/:/g,"\t"); 

                                                                                for (var a = 1; a < pstyles.length; a++) { 

                                                                                          if (pstyles[a].appliedFont.name==ffont) { 

                                                                                                    pstyles[a].appliedFont = tfont;                                       

                                                                                                   

                                                                                  var pstyles = doc.allParagraphStyles; 

                                                                                var cstyles = doc.allCharacterStyles; 

                                                                                var ffont = myFindDrop6.selection.text.replace(/:/g,"\t"); 

                                                                                var tfont = myChDrop6.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'); 

                                                            • 33. Re: Specified font need to be changed in all paragraph styles
                                                              tpk1982 Level 4

                                                              ok try this..

                                                               

                                                              simple find and replace for all opened documents.. this will give you the hint

                                                               

                                                              for(i=0; i< app.documents.length; i++){

                                                              app.findGrepPreferences = null;     app.changeGrepPreferences = null; 

                                                              app.findGrepPreferences.findWhat="a";

                                                              app.changeGrepPreferences.changeTo  = "b";

                                                              app.documents[i].changeGrep(); 

                                                              }

                                                              • 34. Re: Specified font need to be changed in all paragraph styles
                                                                Obi-wan Kenobi Adobe Community Professional

                                                                Based on Vlad's clever script, this version loops through all open docs and demands what to do after having extracted the list of fonts used in the current doc:

                                                                 

                                                                function main(){  
                                                                  var docs = app.documents;
                                                                
                                                                  for (var d = docs.length-1; d >= 0; d--) {
                                                                          var doc=docs[d];  
                                                                          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');  
                                                                
                                                                

                                                                 

                                                                 

                                                                (^/)

                                                                • 35. Re: Specified font need to be changed in all paragraph styles
                                                                  Suzan.V Level 1

                                                                  Dear Obi-wan, thanks a lot for your generous help but your code asks what do to for each document, i was seeking to apply first modification to all other files without asking again and again for each file

                                                                   

                                                                   

                                                                  sorry guys for bothering you all, i'm intending to get it with your help or with my efforts as possible i can

                                                                   

                                                                   

                                                                  • 36. Re: Specified font need to be changed in all paragraph styles
                                                                    Obi-wan Kenobi Adobe Community Professional

                                                                    Vlad,

                                                                     

                                                                    Maybe your answer was a little bit angry but I totally agree with you!

                                                                     

                                                                    (^/) 

                                                                    • 37. Re: Specified font need to be changed in all paragraph styles
                                                                      Obi-wan Kenobi Adobe Community Professional

                                                                      I don't think it's a good way to do like you want, especially if the chosen font(s) don't exist in a doc! 

                                                                      In this case, we need more scripting: play the script until it doesn't find the font(s)! … and, in this situation, what does the script do?

                                                                       

                                                                      (^/)

                                                                      • 38. Re: Specified font need to be changed in all paragraph styles
                                                                        Suzan.V Level 1

                                                                        I don't think it's a good way to do like you want, especially if the chosen font(s) don't exist in a doc!

                                                                        i think that is not a problem because i'm working on a large project with many files contain same fonts on each file

                                                                        • 39. Re: Specified font need to be changed in all paragraph styles
                                                                          Skemicle Level 3

                                                                          Suzan.V,

                                                                          Obi-Wan has given you all the information you need to modify the script the way you want it.. simply moving lines 4 and 5 will change the starting point of the for() loop If that's what you really want to do.. using that you can choose what you want to repeat for each document.. just make sure you move line 34 to the appropriate ending point of the loop.

                                                                           

                                                                          Vamitul and Obi-wan Kenobi,

                                                                          clicking the cancel button in your scripts still executes the script.

                                                                          if (myDialog.show()) {
                                                                          
                                                                          

                                                                          Should be changed to:

                                                                          if(myDialog.show() != 1){
                                                                              exit()
                                                                          }else{
                                                                          
                                                                          1 2 Previous Next