8 Replies Latest reply on Jul 21, 2015 6:45 AM by DooGz

    Find format preferences in a Find/Change GREP script?

    DooGz

      Hi all,

       

      I'm creating my first Find/Change script to handle several GREP queries at once. But I'm struggling to work out how to specify the Find Format: preference in the script as one can in the usual Find/Change dialog box.

       

      Here's a sample line in my script. What I'm trying to achieve is for this line to search for characters/words that currently have the [Basic Paragraph] applied to it, and then change the format to a particular paragraph style, which I've called "Team name" ...

       

      grep     {findWhat:"(.+)", appliedParagraphStyle:"[Basic Paragraph]"}     {changeTo:"$1", appliedParagraphStyle:"Team name"}     {}     // apply Team name style

       

      Btw, I'm using the standard FindChangeByList script that comes with Indesign. All help/feedback is appreciated.

       

      Cheers,

      Marco

        • 1. Re: Find format preferences in a Find/Change GREP script?
          Peter Spier Most Valuable Participant (Moderator)

          moved to the scripting forum...

          • 2. Re: Find format preferences in a Find/Change GREP script?
            DooGz Level 1

            Forgot to mention that what that line is currently doing is changing ALL text to the new paragraph style, instead of just text that is currently formatted as [Basic Paragraph].

            • 3. Re: Find format preferences in a Find/Change GREP script?
              Peter Kahrel Adobe Community Professional & MVP

              You probably need to escape the brackets: "\[Basic Paragraph\]".

              Peter

              • 4. Re: Find format preferences in a Find/Change GREP script?
                DooGz Level 1

                Thanks Peter. And that makes sense to me too as I got a bit excited with your suggestion ... but unfortunately it didn't change the result. All text is being changed to the new style, instead of just text that has [Basic Paragraph] applied. Hopefully others might have suggestions? I still haven't been able to find samples of similar GREP script that shows how to set 'find format' prefs.

                • 5. Re: Find format preferences in a Find/Change GREP script?
                  Peter Kahrel Adobe Community Professional & MVP

                  It doesn't seem to work at all. In this code:

                   

                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  app.findGrepPreferences.appliedParagraphStyle = '\[Basic Paragraph\]';
                  app.changeGrepPreferences.appliedParagraphStyle = 'Team name';
                  app.documents[0].changeGrep();
                  

                   

                  no matter how you specify the Basic Paragraph by name throws an error ('Basic paragraph', '[Basic paragraph]', '[\Basic paragraph\]'). But you can always use code like this:

                   

                  app.findGrepPreferences = app.changeGrepPreferences = null;
                  app.findGrepPreferences.appliedParagraphStyle = app.documents[0].paragraphStyles[1];
                  app.changeGrepPreferences.appliedParagraphStyle = 'Team name';
                  app.documents[0].changeGrep();
                  

                   

                  (paragraphStyles[0] is [No Paragraph Style]). There's no need to specify the find and replace strings, by the way, similar to how you would do it in the interface.

                  You are aware, I hope, that applying styles like this removes local formatting. If you want to keep any local formatting you need a different approach.

                   

                  Peter

                  • 6. Re: Find format preferences in a Find/Change GREP script?
                    DooGz Level 1

                    Yep. Perhaps I didn't explain it clearly enough or I'm just confused myself.

                     

                    I'm trying to utilise the FindChangeByList.jsx script found in Indesign's default list of scripts. This script points to the FindChangeList.txt file which contains a simple list of GREP expressions that our carried out when the script is run. I'm basically modifying this text file to incorporate my own list of GREP expressions that I want carried out for my own purposes.


                    The text file contains some basic examples already on how to specify things that you'd normally do in a Find/Change dialog box. I know that the following line will find any character that currently has the style "example-style" applied to it and change the style to "new-style".

                     

                    grep    {findWhat:"(.+)",appliedParagraphStyle:"example-style"}    {changeTo:"$1",appliedParagraphStyle:"new-style"}    {}

                     

                    But I'm struggling to determine how to make it look for characters that have the [Basic Paragraph] applied to them. Peter, I thought your idea of escaping the square brackets would work in this case.

                     

                    Here's a screenshot of the default script in Indesign, and the text file of GREP expressions that it points to. Here's a link to the FindChangeList.txt file for convenience but it's in every installation of Indesign as well anyway.

                    listofscripts.jpg

                     

                    And here's the section of the Find/Change dialog box in Indesign that I'm trying to set as a GREP expression in that text file. You can see that I can set it to find only those characters with the [Basic Paragraph] applied to them.

                     

                    My question is, how do I do that in the FindChangList text file?

                     

                    findchangedialogbox.jpg

                    • 7. Re: Find format preferences in a Find/Change GREP script?
                      Peter Kahrel Adobe Community Professional & MVP

                      Instead of the style's name, try the paragraph style object:

                       

                      grep    {findWhat:"(.+)",appliedParagraphStyle:app.documents[0].paragraphStyles[1]}    {changeTo:"$1",appliedParagraphStyle:"new-style"}    {}

                       

                      Peter

                      • 8. Re: Find format preferences in a Find/Change GREP script?
                        DooGz Level 1

                        Peter ... you're a *******' legend. That worked perfectly. Now I know how to target any styles in my document that haven't yet been properly styled. Thanks heaps!