5 Replies Latest reply on May 5, 2009 6:48 AM by johnBking78

    Find a Para style and change it to another

    johnBking78 Level 1

      I have a group of imported styles (paragraph & Character) and want to automatically change them to another:

       

      Paragraph Styles

      Heading 1 = ChapterHeader

      Heading 2 = aHeader

      Heading 3 = bHeader

      Number 8 = paraNumbered8

       

      Character Styles

      Bold = 00-BoldText

      Italic = 00-ItalcText

       

      I have used this script which word up to the point a style is missing from the imported text (say Heading 2) it will stop and error:

       

      // Headers styles
      #target indesign;
      app.findTextPreferences = app.changeTextPreferences = null;
      app.findChangeTextOptions.includeFootnotes = true;
      app.findChangeTextOptions.includeHiddenLayers = true;
      app.findChangeTextOptions.includeMasterPages = true;
      app.findTextPreferences.appliedParagraphStyle = "Heading 1 NoNumber";
      app.changeTextPreferences.appliedParagraphStyle = "00 - Chapter Title";
      app.documents[0].changeText();
      app.findTextPreferences.appliedParagraphStyle = "Heading 1";
      app.changeTextPreferences.appliedParagraphStyle = "00 - Chapter Title Numbered";
      app.documents[0].changeText();
      app.findTextPreferences.appliedParagraphStyle = "Heading 2";
      app.changeTextPreferences.appliedParagraphStyle = "01 - A Heads";
      app.documents[0].changeText();
      app.findTextPreferences.appliedParagraphStyle = "Heading 3";
      app.changeTextPreferences.appliedParagraphStyle = "02 - B Heads";
      app.documents[0].changeText();
      app.findTextPreferences.appliedParagraphStyle = "Number 8";
      app.changeTextPreferences.appliedParagraphStyle = "paraNumbered8";
      app.documents[0].changeText();
      /*Clear the find/change preferences after the search.*/
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing
      

       

      Error message when "Number 8" para style is missing:

       

      Picture 1.png

       

       

      Any help would fantastic, I am very very new to this!

       

       

      Kind Regards.

        • 1. Re: Find a Para style and change it to another
          Harbs. Level 6

          I'd approach this like this:

           

          var style = doc.paragraphStyles.item("Heading 1");

          var targetStyle = doc.paragraphStyles.item("ChapterHeader");

          style.remove(targetStyle);

           

          Do this for each set of styles...

           

          Harbs

          • 2. Re: Find a Para style and change it to another
            Dave Saunders Level 4

            I think the specific cause of the error message is that your style is not called "Number 8" or it is buried in style group and so can't be addressed in the way you're doing it.

             

            Dave

            • 3. Re: Find a Para style and change it to another
              johnBking78 Level 1

              Thanks Harbs,

               

              That works but I don't want to remove the old style, how would I go about changing? I've tried removing just "style.remove(targetStyle);" but then it would not work.

               

              again many thanks.

               

               

              Adam

              • 4. Re: Find a Para style and change it to another
                René Mølsted Level 1

                Have you tried this approach?

                // Headers styles
                 
                #target indesign;
                
                app.findTextPreferences = app.changeTextPreferences = null;
                app.findChangeTextOptions.includeFootnotes = true;
                app.findChangeTextOptions.includeHiddenLayers = true;
                app.findChangeTextOptions.includeMasterPages = true;
                
                try {
                     app.findTextPreferences.appliedParagraphStyle = "Heading 1 NoNumber";
                     app.changeTextPreferences.appliedParagraphStyle = "00 - Chapter Title";
                     app.documents[0].changeText();
                     
                     /*Clear the find/change preferences after the search.*/
                     app.findTextPreferences = NothingEnum.nothing;
                     app.changeTextPreferences = NothingEnum.nothing
                }  catch(err){}
                
                try {
                     app.findTextPreferences.appliedParagraphStyle = "Heading 2";
                     app.changeTextPreferences.appliedParagraphStyle = "01 - A Heads";
                     app.documents[0].changeText();
                     
                     /*Clear the find/change preferences after the search.*/
                     app.findTextPreferences = NothingEnum.nothing;
                     app.changeTextPreferences = NothingEnum.nothing
                } catch(err){}
                
                try {
                     app.findTextPreferences.appliedParagraphStyle = "Heading 3";
                     app.changeTextPreferences.appliedParagraphStyle = "02 - B Heads"
                     app.documents[0].changeText();
                     
                     /*Clear the find/change preferences after the search.*/
                     app.findTextPreferences = NothingEnum.nothing;
                     app.changeTextPreferences = NothingEnum.nothing
                } catch(err){}
                
                try {
                     app.findTextPreferences.appliedParagraphStyle = "Number 8";
                     app.changeTextPreferences.appliedParagraphStyle = "paraNumbered8";
                     app.documents[0].changeText();
                     
                     /*Clear the find/change preferences after the search.*/
                     app.findTextPreferences = NothingEnum.nothing;
                     app.changeTextPreferences = NothingEnum.nothing
                } catch(err){}
                
                

                 

                --

                molsted

                • 5. Re: Find a Para style and change it to another
                  johnBking78 Level 1

                  Fantastic, that worked a treat!

                   

                   

                  Thank you very much René Mølsted!!

                   

                   

                  Regards,

                   

                   

                  Adam