Skip to main content
Participant
December 23, 2024
Question

My GREP with style restriction does not work in InDesign server

  • December 23, 2024
  • 3 replies
  • 801 views

Hi.

I want to replace the strings ": " or "- " by a carriage return when the style applied to the test is "GROUP1:SUBGROUP1:title2".

I have a stored GREP with the following properties:

  • Find waht: (: |- )
  • Change to: \n
  • Find Format: Paragraph Style: title2 (GROUP1:SUBGROUP1)
  • Include footnotes: enabled

This GREP is called within a script.

app.loadFindChangeQuery ("tempGrep", SearchModes.GREP_SEARCH);
app.documents[0].changeGrep();

It works fine in InDesign desktop (version 20.0.1 and 19.5.1). It returns 3 occurrences.

It does not work in InDesig server (version 20.0.0.95). It returns 1080 occurrences.

I have also tried to not use the stored GREP but configure the properties in a script:

app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
app.findChangeGrepOptions.kanaSensitive = false;
app.findChangeGrepOptions.widthSensitive = false;
app.findGrepPreferences.findWhat = "(: |- )";
app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyleGroups.item('GROUP1').paragraphStyleGroups.item('SUBGROUP1').paragraphStyles.item('title2');
app.changeGrepPreferences.changeTo = "\n";
app.documents[0].changeGrep();

It does not even work on desktop, also 1080 occurrences.

I have attached the stored GREP file.

Am I missing something?

Is there a bug in InDesign server?

 

Thanks in advance for any help.

This topic has been closed for replies.

3 replies

Participant
December 26, 2024

Thanks all for your quick response, I didn't expect it on this days.

 

I modified the assignment of the property appliedParagraphStyle to findTextPreferences instead of to findGrepPreferences and it works in InDesign desktop and in InDesign server.

 

Now my concern is that I have 26 GREPs stored. If I have to move them to scripts it will be a bit costly.

Do you have any idea why InDesign server does not correctly process GREPs stored with style restriction?

If there is no immediate solution I will have to create a function that reads the XML from the GREPs and converts them to Json to execute.

 

Thanks in advance.

Peter Kahrel
Community Expert
Community Expert
December 26, 2024

Do you have any idea why InDesign server does not correctly process GREPs stored with style restriction?

If ID Desktop works with the wrong style assignment and ID Server does not, I would say that the problem is with ID Desktop. But I suspect that the problem was in not resetting the find.change preferences.

 

It seems to me that running those 26 queries is much less efficient than running a single script that executes those queries. Reading those XML queries to collect the find and change texts into a single script is not too difficult. See this script:

https://creativepro.com/files/kahrel/indesign/grep_query_manager.html

to see how that works (if you don't know that already, of course!).

 

As a sidenote, characer classes are on the whole more efficient than 'or' statements. So instead of (: |- ) try [:-]\x20 (where \x20 stands for the space character, I use it here just so you can see where the space goes).

Participant
December 26, 2024

Thanks Peter.

I didn't put in my first post, but in my script there are reset instructions.

app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;

Before and after the GREP code.

 

I put the GREP as script code as calling the stored GREP didn't work in InDesign server when a style restriction is set.

Seems that the loadFindChangeQuery instruction is not loading the style restriction in InDesign server.

app.loadFindChangeQuery ("tempGrep", SearchModes.GREP_SEARCH);

I works correctly in InDesign desktop applying the change just in the points with the specified style.

 

Thanks for pointing me to the query manager.

 

Good point on refactoring the find to [:-]\x20.

brian_p_dts
Community Expert
Community Expert
December 23, 2024

You need to escape backslashes in your strings with a second backslash, ie. \\n

 

Edit: I'm wrong as Peter notes

m1b
Community Expert
Community Expert
December 23, 2024

Ah! Yes! You got it. 🙂

Peter Kahrel
Community Expert
Community Expert
December 23, 2024

That's not the casefor \r, \n, and \t. The only thing is that you won't see those 'characters' in the Find/Change window, but the query works fine.

m1b
Community Expert
Community Expert
December 23, 2024

Hi @miguel_4366 I'm not at my computer so I haven't tested, but can you try this:

 

 

function main() {

    var doc = app.documents[0];

    var targetStyle = doc.paragraphStyleGroups.item('GROUP1').paragraphStyleGroups.item('SUBGROUP1').paragraphStyles.item('title2');

    if (!targetStyle.isValid)
        return $.writeln('Target style cannot be found.');

    app.findGrepPreferences = NothingEnum.NOTHING;
    app.changeGrepPreferences = NothingEnum.NOTHING;

    app.findChangeGrepOptions.properties = {
        includeFootnotes: false,
        includeHiddenLayers: false,
        includeLockedLayersForFind: false,
        includeLockedStoriesForFind: false,
        includeMasterPages: false,
        kanaSensitive: false,
        widthSensitive: false,
    };

    app.findGrepPreferences.properties = {
        findWhat: "(: |- )",
        appliedParagraphStyle: targetStyle,
    };

    app.changeGrepPreferences.properties = {
        changeTo: "\n",
    }

    doc.changeGrep();

}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Find/Change Title2');

 

 

Note I only tried this on Indesign desktop, not server. If it works, then perhaps the only problem was either (a) switching to app.findTextPreferences for the applied paragraph style, and/or (b) not resetting the find and change grep preferences before starting, so the previous find/change properties could have been interfering.

- Mark