2 Replies Latest reply on Sep 10, 2014 9:32 PM by Tim. Signore

    Replacing based on style

    Tim. Signore Level 1


      I have a series of documents in which a number of stylesheets are based on "Basic Paragraph". I want to change them all to be based on No Paragraph Style. The script below targets the correct folder (Fonts, within General), but there is something wrong with my syntax in the loop (line 15).


      Thanks in advance for any help with this.



      var myDoc = app.activeDocument;
      var theseStyles = myDoc.paragraphStyleGroups.itemByName ("General");
      var targetStyles = theseStyles.paragraphStyleGroups.itemByName("Fonts");
      var numberStyles = targetStyles.allParagraphStyles.length;
      for  (var i = 0; i<numberStyles; i++){
          var currentStyle = targetStyles.allParagraphStyles[i];
          if (currentStyle.basedOn = "Basic Paragraph"){
              currentStyle.basedOn = "No Paragraph Style";
        • 1. Re: Replacing based on style
          Chinnadk Level 4

                 if (currentStyle.basedOn = "Basic Paragraph"){ 

                  currentStyle.basedOn = "No Paragraph Style";


          Change these two lines like below


              if (currentStyle.basedOn = myDoc.paragraphStyles.item("[Basic Paragraph]")){ 

                  currentStyle.basedOn =  myDoc.paragraphStyles.item("[No Paragraph Style]"); 

          • 2. Re: Replacing based on style
            Tim. Signore Level 1

            Thanks Chinnadk - that works now. But am i right in thinking that you have replicated my original mistake, and the first line should read:


            if (currentStyle.basedOn == myDoc.paragraphStyles.item("[Basic Paragraph]")){

            ie. two equals signs to test truth, rather than one to assign value.