• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

GREP search crashes InDesign

Contributor ,
Nov 19, 2012 Nov 19, 2012

Copy link to clipboard

Copied

Hi,

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 = "";

app.activeDocument.changeGrep();

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.

TOPICS
Scripting

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Nov 20, 2012 Nov 20, 2012

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.

Votes

Translate

Translate
Advisor ,
Nov 20, 2012 Nov 20, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 20, 2012 Nov 20, 2012

Copy link to clipboard

Copied

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.

Cheers,

Simon.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 20, 2012 Nov 20, 2012

Copy link to clipboard

Copied

LATEST

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.

Regards,

Simon.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines