5 Replies Latest reply on Aug 21, 2013 5:00 AM by Asher31

    about paragraph style?

    govind_85

      Hello ,

      i want to check wheather particular style is present in the document.if present then i want to apply another style.

      is any method in the indesign script which will find and replce particular style in the document?

        • 1. Re: about paragraph style?
          Kasyan Servetsky Level 5

          You can do this in the find-change dialog box (no script needed). Set a paragraph style you want to find and the one you want to replace it with. Put nothing into the find what and change to fields.

          • 2. Re: about paragraph style?
            govind_85 Level 1

            Hello sir,

            i want to change style by scripting.

            • 3. Re: about paragraph style?
              Kasyan Servetsky Level 5

              Here's a simple example:

              var doc = app.activeDocument;
              app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
              app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyles.item("Header");
              app.changeTextPreferences.appliedParagraphStyle = doc.paragraphStyles.item("Subheader");
              doc.changeText();
              app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
              

               

              It changes paragraph style Header with Subheader

              If you want to reference a paragraph style in a group, you can do this like so:

              app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyleGroups.item("Headers").paragraphStyles.item("Header");
              
              • 4. Re: about paragraph style?
                richardh6 Level 1

                And if you're operating in an environment where you know that you don't have any paragraph styles with the same names stored in different groups, and you want to reference a paragraph style that is somewhere in the document, without knowing what group it's in, you can use this recursive function to find it:

                 

                var findParagraphStyle = function( obj, name ) {
                    var style = obj.paragraphStyles.itemByName( name );
                    if (!style.isValid) {
                        for (var i = 0; i < paragraphStyleGroups.length; i += 1) {
                            style = findParagraphStyle( obj.paragraphStyleGroups[i], name );
                        }
                    }
                    return style; //     If we haven't found a style with name "name", 
                                        //     findParagraphStyle will return an invalid object.
                };
                
                app.findTextPreferences.appliedParagraphStyle = findParagraphStyle( doc, "Header" );
                
                • 5. Re: about paragraph style?
                  Asher31

                  Hey there, i used that first script you added to do what it was meant to and it worked a treat, so thank you, but i wanted to ask what i would have to do to add extra styles to change in the same script? If thats not possible is there a script i could use to run multiple scripts at the same time?

                   

                  Cheers in advance