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

Re: Search and Replace Character Styles

$
0
0

You should be able to just change CharacterStyle to ParagraphStyle. i.e, instead of app.activeDocument.characterStyles.item, it would be app.activeDocument.paragraphStyles.item, etc. It should be that simple.

 

Below is the entire script I'm currently using. I've refined it so that it checks to see if a document has changed and then saves it and then closes it. When the script is finished, I have an entire book that is ready to export to a print PDF.

 

myBookFile = File.openDialog("Choose the BOOK File", "INDB:*.indb", false);

var myDoc=[];

if(myBookFile != null){ 

    app.open(File(myBookFile.fullName.toString()));

    var myBook = app.activeBook

    for(var n=0; n < myBook.bookContents.length; n++)

    {

        myDoc[n] = app.open(File(myBook.bookContents[n].fullName.toString()));

       var i, myFindStyle, myChangeStyle,
       arr = [   ["CrossReference", "BoldUnderline"],
                    ["CrossReferenceBoldItalic", "BoldItalicUnderline"],
                    ["CrossReferenceBoldItalicCaps", "BoldItalicCaps"],
                    ["CrossReferenceCaps", "BoldCaps"],
                    ["CrossReferenceIndex", "Italic"],
              ];
               
       for (i = 0; i < arr.length; i++) {       
             myFindStyle = app.activeDocument.characterStyles.item(arr[i][0]);
             myChangeStyle = app.activeDocument.characterStyles.item(arr[i][1]);
   
            if (myFindStyle.isValid && myChangeStyle.isValid) {
                app.findGrepPreferences.appliedCharacterStyle = myFindStyle;
                app.changeGrepPreferences.appliedCharacterStyle = myChangeStyle;
                app.activeDocument.changeGrep();
            }

       }
      var i, myFindStyle, myChangeStyle,
       arr = ["CrossReferenceProcedure", "CrossReferenceSection"];
      myChangeStyle = app.activeDocument.characterStyles[0];         
       for (i = 0; i < arr.length; i++) {       
             myFindStyle = app.activeDocument.characterStyles.item(arr[i]);
   
            if (myFindStyle.isValid && myChangeStyle.isValid) {
                app.findGrepPreferences.appliedCharacterStyle = myFindStyle;
                app.changeGrepPreferences.appliedCharacterStyle = myChangeStyle;
                app.activeDocument.changeGrep();
            }
       }

     if (app.activeDocument.modified==true) {
          app.activeDocument.save();
          }
      app.activeDocument.close();       

    }

}
else{

    alert("Please select the book file properly !!!");

}

 

Hope this answers your question.


Viewing all articles
Browse latest Browse all 37788

Trending Articles



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