3 Replies Latest reply on Nov 20, 2012 1:33 PM by Angusdog

    GREP search crashes InDesign

    Angusdog Level 1



      I have a script which imports XML and formats it. As part of the formatting, there's numerous GREP searches which remove redundant spaces, returns and so on.


      One in particular crashes InDesign and it's driving me nuts.


      It's supposed to remove redundant returns in a table:


      // GREP Search for redundant returns

      app.findGrepPreferences = app.changeGrepPreferences = null;      

      app.findGrepPreferences.appliedParagraphStyle = "ArticleMinister";

      app.findGrepPreferences.findWhat = "\r$";

      app.changeGrepPreferences.changeTo = "";



      The problem is there's an XML closing tag between the carriage return and the end of the para, i.e. data{return}</closingtag>, but it works fine when the XML is data</closingtag>{return}.


      Any assistance would be most appreciated.

        • 1. Re: GREP search crashes InDesign
          Vamitul Level 4

          hmm.. i can tell you why it happens, but fixing.. hm..

          your search removes not only the "{return}" but also the closing tag, so the XML becames invalid.

          simple fix: edit the xml first moving all closing tags before the return char.

          harder fix.. something like get all XMLElements, check if the last char in xmlContents=='\r', check if it is at the end of the story, remove it.

          • 2. Re: GREP search crashes InDesign
            Angusdog Level 1

            Hi Vamitul,


            Thanks very much for the reply and it makes perfect sense.


            This script creates quite a complex document and, for some reason, moving the {return} outside the XML tags makes a mess of the document. I do not know why but I suspect that some of the 'clean up' non-GREP search and replace commands in the script are ignoring the XML data - perhaps not but I cannot for the life of me work out why a simple change is making the text a real mess.


            So the 'harder fix' sounds like something worth pursuing as this is the last step in a long process. Do you have any more information about checking the xmlContents? I don't expect anyone else to do my work for me, but advanced (or even intermediate) scripting is something I struggle with.





            • 3. Re: GREP search crashes InDesign
              Angusdog Level 1

              Okay, neither of the options made in into my final script. Moving the {return} code outside the tag just caused major mayhem in the most odd fashion. Totally flummoxed as to why (added extra returns all over the place, even several XML tags back).


              Learning how to handle searching inside the XMLelements was beyond me at this stage and with this deadline.


              So I moved my custom control codes around, changed a paragraph style to a character style and managed to get a result.


              I will come back to learning about XMLelements as it sounds useful to have as a skill and thanks very much for your help.