Skip to main content
John D Herzog
Inspiring
December 23, 2024
Answered

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

  • December 23, 2024
  • 1 reply
  • 609 views

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.
This topic has been closed for replies.
Correct answer m1b

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

1 reply

brian_p_dts
Community Expert
Community Expert
December 24, 2024

You need to escape the backslashes, ie \\d

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
December 24, 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

John D Herzog
Inspiring
December 24, 2024

Thank you! GREP is still magic to me.