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

Delete multiple Em Spaces not working when called outside InDesign

Community Beginner ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

368

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

Community Beginner , Jul 12, 2018 Jul 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!

Votes

Translate

Translate
Contributor ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

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

via doScript() you call your function()

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
Community Beginner ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

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

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
Community Expert ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

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}.

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
Community Beginner ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

LATEST

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!

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