Skip to main content
John D Herzog
Inspiring
Dec 23, 2024 11:04 PM UTC
Answered

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

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 is closed to new replies. Start a new post to keep the conversation going.
m1b
m1bCorrect answer
Community Expert
Dec 24, 2024 1:53 AM UTC

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

5 replies

brian_p_dts
Community Expert
Community Expert
Dec 24, 2024 12:52 AM UTC

You need to escape the backslashes, ie \\d

Translate
m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Dec 24, 2024 1:53 AM UTC

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
John D Herzog
Inspiring
Dec 24, 2024 5:42 PM UTC

Thank you! GREP is still magic to me.

Translate