11 Replies Latest reply on Sep 11, 2015 3:49 AM by 0201m

    InDesign CC 2015 - Font replace Script

    0201m

      Hello everyone,

      I am currently having Trouble getting my once under CS6 running Font Replace Script to work.

      The font that I want is installed and I can Change it manually in the document, however when I let the script do it for me he cant find the font and even searching it manually won't work as it only Shows me fontStyle "Regular" then

       

      var myFolder = Folder.selectDialog( "Select a folder with InDesign files" );  
      if ( myFolder != null ) {  
           var myFiles = [];  
             
           GetSubFolders(myFolder);  
      }  
        
      //=================================== FUNCTIONS =========================================  
      function GetSubFolders(theFolder) {  
           var myFileList = theFolder.getFiles();  
           for (var i = 0; i < myFileList.length; i++) {  
                var myFile = myFileList[i];  
                if (myFile instanceof Folder){  
                     GetSubFolders(myFile);  
                }  
                else if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {  
                     myFiles.push(myFile);  
                }  
           }  
      } 
       for (var i = 0; i < myFiles.length; i++) {  
           myFile = myFiles[i];
           app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
           doc = app.open(myFile)
           app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
           app.findTextPreferences = NothingEnum.nothing;
           app.changeTextPreferences = NothingEnum.nothing;
           app.findTextPreferences.appliedFont = "Bauhaus LT Demi Regular";
           app.changeTextPreferences.appliedFont = "Futura BQ Book";
           app.activeDocument.changeText();
           doc.close(SaveOptions.YES);
      } 
      

       

      Can anybody help me, did something in the Scripting toolkit for OpenType Fonts Change?

      Btw, even Setting to font Style as a second Attribute won't work

       

      Thanks in advance,

      MArco

        • 1. Re: InDesign CC 2015 - Font replace Script
          S Hopkins Adobe Community Professional

          No consolation, here. I am also having problems. Looks like the functionality is broken. I will post again once I have done more tests. Thanks for bringing this to my attention. I am afraid that a number of my scripts have been broken since version 6.0.

          • 2. Re: InDesign CC 2015 - Font replace Script
            0201m Level 1

            Good that I'm not alone, already thought I messed something up with Windows 10 and the font installation.

             

            I hope this is fixable as I need to update approx. 200 datasheets as our new CI involves a new font.

            • 3. Re: InDesign CC 2015 - Font replace Script
              Vamitul Level 4

              Before changing the font, try doing a save to idml->save to indd->replace fonts.

              • 4. Re: InDesign CC 2015 - Font replace Script
                0201m Level 1

                Ok, I'll try that, what are the commands for saving the IDML (sorry pretty new to adobe scripting).

                Is it advised to do so? Before, on CS6, I simply did "Open indd" -> "Replace font" -> "Overwrite existing indd" without troubles

                • 5. Re: InDesign CC 2015 - Font replace Script
                  Vamitul Level 4

                  first, try it by hand on a few documents to know if it works.

                  • 6. Re: InDesign CC 2015 - Font replace Script
                    0201m Level 1

                    As said above when I open it manually, mark the text, change to font and overwrite the existing file everything works perfectly.

                    Only with the script it kind of "destroys" the document meaning even opening the document and trying to rescue it afterwards won't work as it only gives me the option "Futura BQ" "Regular" in the popup where InDesign says that it can't find a font in the document.

                    When I select Futura Regular even that won't work as it seem to be some kind of "generic" option, because the Futura BQ doesn't have a "Regular" font type.

                    • 7. Re: InDesign CC 2015 - Font replace Script
                      0201m Level 1

                      What I saw is that when I select the the font by hand on the top left it stands in the box as "Futura BQ" and "Book".

                      After the script I get "[Futura BQ]" and "[Regular]"

                      • 8. Re: InDesign CC 2015 - Font replace Script
                        S Hopkins Adobe Community Professional

                        After some testing I find that most fonts work as expected. However, there are some that do not. The clue seems to be that for some reason InDesign sees the font as being NOT_AVAILABLE (see FontStatus). You can see how to test the font status in the script below.

                         

                        var docRef = app.documents.item(0);

                        app.findTextPreferences = app.changeTextPreferences = null;  

                        app.findTextPreferences.appliedFont = "Avenir"; 

                        app.findTextPreferences.fontStyle = "Light";

                        app.changeTextPreferences.appliedFont = "Minion Pro";

                        app.changeTextPreferences.fontStyle = "Regular";

                        app.findChangeTextOptions.includeFootnotes = true;

                        app.findChangeTextOptions.includeMasterPages = false;

                        app.findChangeTextOptions.includeHiddenLayers = false;

                        app.findChangeTextOptions.wholeWord = true;

                        var myFoundItems = docRef.findText();

                        var fontTest = app.fonts.itemByName("Avenir Roman").status;

                        var myTest = app.fonts.itemByName("Minion Pro Regular").status;//space is a tab

                        if (myFoundItems != "" && myTest == 1718831470){ //INSTALLED

                            docRef.changeText(); 

                        }

                        app.findTextPreferences.appliedFont= app.changeTextPreferences = null;

                        //for testing

                        myFoundItems;

                         

                        Hope this helps.

                        • 9. Re: InDesign CC 2015 - Font replace Script
                          0201m Level 1

                          Thanks a lot, somehow that did the trick

                           

                          var docRef = app.documents.item(0);

                          app.findTextPreferences = app.changeTextPreferences = null;  

                          app.findTextPreferences.appliedFont = "Bauhaus LT Demi"; 

                          app.findTextPreferences.fontStyle = "Regular";

                          app.changeTextPreferences.appliedFont = "Futura BQ";

                          app.changeTextPreferences.fontStyle = "Book";

                          app.findChangeTextOptions.includeFootnotes = true;

                          app.findChangeTextOptions.includeMasterPages = false;

                          app.findChangeTextOptions.includeHiddenLayers = false;

                          app.findChangeTextOptions.wholeWord = true;

                          var myFoundItems = docRef.findText();

                          var fontTest = app.fonts.itemByName("Bauhaus LT Demi    Regular").status;

                          var myTest = app.fonts.itemByName("Futura BQ").status;//space is a tab

                          if (myFoundItems != "" && myTest == 1718831470){ //INSTALLED

                              docRef.changeText(); 

                          }

                          app.findTextPreferences.appliedFont= app.changeTextPreferences = null;

                          //for testing

                          myFoundItems;

                          • 10. Re: InDesign CC 2015 - Font replace Script
                            0201m Level 1

                            Funny, it worked once and now on the same document (did a Backup before) it failed again, like my script did. Even InDesign itself won't recognize the font if I reopen everything and select it manually.

                            When I run the script with the Font to be replaced still in the document it Returns "[object Paragraph]", which is ok, running it a second timne return "undefined" which is also ok, as the text now changed (although the font is corrupted/missing)

                             

                            Somehow the replacing Action itself seems to corrupt something in InDesign Font library

                            • 11. Re: InDesign CC 2015 - Font replace Script
                              0201m Level 1

                              I found a pattern on how to reproduce the "bug"

                              Open InDesign & Scripting toolkit -> Run fontreplace script -> Broken font -> Manually replacing it won't work

                              Open InDesign & Scripting toolkit -> Replace font manually (InDesign finds the font) -> Ctrl + Z to revert to old font -> Run replacing script -> Bingo, font gets replaced + isn't broken

                               

                              Does InDesign somehow not load the Fonts that aren't in use in the active document?