Skip to main content
Participant
July 12, 2018
Answered

Delete multiple Em Spaces not working when called outside InDesign

  • July 12, 2018
  • 3 replies
  • 475 views

Hello! , I'm having an issue with a particular grep expression that doesn't seem to work when I try to execute via an external call, but id does work fine whenever I execute inside InDesign.

My script aims to delete multiple em spaces and replaces them with a normal space.

function deleteDoubleEmSpaces() {

    //var doc = app.activeDocument;   

    var doc = app.documents.itemByID(iddoc);

    findChangeGrep("~>{2,}"," ","","","","");

}

function findChangeGrep(findWhat, changeTo, findStyle, changeStyle, findChrStyle, changeChrStyle) {

    var doc = app.documents.itemByID(iddoc);

    //var doc = app.activeDocument;

    try {

        app.findGrepPreferences.findWhat = findWhat;

        app.changeGrepPreferences.changeTo = changeTo;

        if (findStyle) app.findGrepPreferences.appliedParagraphStyle = findStyle;

        if (changeStyle) app.changeGrepPreferences.appliedParagraphStyle = changeStyle;

        doc.changeGrep();

    } catch (e) {}

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

}

If I run this via the script console from InDesign, it works ok. The regex seems to work fine in the find and change menu. I have other scripts that are called in the same way, and work fine. 

Also, I have used this findChangeGrep() with a simplified grep, and also works.

My guess is that I have to call the em spaces different, but I can't find how. I have tried things like \\~\\>{2,} ; \\~>{2, }, but nothing seems to works.

The execution of this script is being made via C# , with a indd.DoScript() method, where indd is an instance of my Indesign App.

Any clues on where is the mistake? Thanks!

This topic has been closed for replies.
Correct answer NicoGallegos

Well... found the "error".  The script is just working fine, as everyone suggested.  The issue is that my original Word Document has one en space, and in the template footnote preferences, it was set to add an en space as a separator between number an text. That result into two en spaces, and the script "never worked", because when it was executed, the footnotes only had one.

Thanks for your help!

3 replies

NicoGallegosAuthorCorrect answer
Participant
July 12, 2018

Well... found the "error".  The script is just working fine, as everyone suggested.  The issue is that my original Word Document has one en space, and in the template footnote preferences, it was set to add an en space as a separator between number an text. That result into two en spaces, and the script "never worked", because when it was executed, the footnotes only had one.

Thanks for your help!

Jongware
Community Expert
Community Expert
July 12, 2018

Theoretically it should have worked … no matter from where you call the script, it must be running inside InDesign to work.

But careful reading your post shows you may be mistaking one shortcut code for another. Your title and text says you are looking for em-spaces, but the code for an em space is ~m and not ~> (that is for an EN space).

If you are indeed looking for ~>, try the Unicode of the en space instead, noted in ID's GREP as \x{2002}.

payalm68947498
Inspiring
July 12, 2018

You are trying to execute via an external call means what..

via doScript() you call your function()

Participant
July 12, 2018

Yes, I do a indd.doScript , and there is where I call my javascript code with the function