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

I am trying to find a dimension in textFrames in a file using GREP

Engaged ,
Dec 23, 2024 Dec 23, 2024

I have a file I need to find the textFrames that have " - #” x #”" in the frame. Using the F/C GREP I can find them with / - d+.d+” x d+.d+”/. If I try to using it in my script it does not give anything back on the same text frames.

The lines of code where this is used are:

app.findGrepPreferences.findWhat = " - \d+.\d+” x \d+.\d+”";
info = tFrames.item(y).findGrep();
Any help would be appreciated.
TOPICS
Scripting , UXP Scripting
292
Translate
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 Expert , Dec 23, 2024 Dec 23, 2024

Yes, including the period. Something like this:

var doc = app.activeDocument;

app.findGrepPreferences = NothingEnum.NOTHING;

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

app.findGrepPreferences.properties = {
    findWhat: '\\d+(\\.\\d+)?[”"] x \\d+(\\.\\d+)?[”"]',
};

var found = doc.findGrep();
$
...
Translate
Community Expert ,
Dec 23, 2024 Dec 23, 2024

You need to escape the backslashes, ie \\d

Translate
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 ,
Dec 23, 2024 Dec 23, 2024

Yes, including the period. Something like this:

var doc = app.activeDocument;

app.findGrepPreferences = NothingEnum.NOTHING;

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

app.findGrepPreferences.properties = {
    findWhat: '\\d+(\\.\\d+)?[”"] x \\d+(\\.\\d+)?[”"]',
};

var found = doc.findGrep();
$.writeln('found.length = ' + found.length);

for (var i = 0; i < found.length; i++) {
    $.writeln(found[i].contents);
}

Not sure if you need it, but matching typographic quotes might be useful, too.

- Mark

Translate
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
Engaged ,
Dec 24, 2024 Dec 24, 2024

Thank you! GREP is still magic to me.

Translate
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 ,
Dec 24, 2024 Dec 24, 2024

Note that you only have to escape them in script. In the find change panel it would still be \d, etc.

Translate
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
Engaged ,
Dec 24, 2024 Dec 24, 2024
LATEST

Oh, I know. I had worked it out in the find change panel until it worked, then pasted it over and had the issues.

Translate
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