Monday, April 22, 2019

#1 2019-04-10 03:07:52 pm

bebout
Member
From:: San Diego, California
Registered: 2004-11-24
Posts: 18

InDesign CC 2019 - Find GREP on specific page

I am trying to create an index of part numbers (always 6 digits) for each page of a catalog. Is there a way to run find GREP on each individual page of an InDesign document. Telling the page generates a "page doesn't understand" error. I want to end up with a tab separated list with part numbers in the first position and page numbers in the second position. This is what I have. Any help would be greatly appreciated.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set niceList to {}
set finalList to {}
set pageList to {}
tell application "Adobe InDesign CC 2019"

   set find grep preferences to nothing
   set change grep preferences to nothing
   set find what of find grep preferences to "\\d{6}"
   set applied paragraph style of find grep preferences to nothing

   set theDoc to the active document
   tell theDoc
       set thePages to pages of theDoc
       repeat with i in thePages
           set end of pageList to name of i
       end repeat
       repeat with j from 1 to count of items of pageList
           set theList to ""
           
           tell page j of theDoc
               
               set theList to find grep
               repeat with i in theList
                   set end of niceList to ((text of i as string) & tab & (item j of pageList as string))
               end repeat
           end tell
       end repeat
   end tell
end tell

Browser: Safari 537.36
Operating System: macOS 10.14

Offline

 

#2 2019-04-10 04:33:04 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 864

Re: InDesign CC 2019 - Find GREP on specific page

Hi. This mostly works, but you grep a page's text objects, rather than the page itself.
change this:           

 tell page j of theDoc

to this:   

tell theDoc's page j's text frames

You can preview the outcome in the editor by ending your code with "niceList," and, since ASObjC commands aren't used, you can also remove the first two "use" statements.

Offline

 

#3 2019-04-11 09:41:17 am

bebout
Member
From:: San Diego, California
Registered: 2004-11-24
Posts: 18

Re: InDesign CC 2019 - Find GREP on specific page

Thanks Marc - I tried that and got nothing because everything in my test spread is in a table (the whole project will be a mix of regular text frames and tables). I tried

Applescript:

tell theDoc's page j's tables

and got "every table of page 1 of document id 3 doesn't understand the "find grep" message.

Last edited by bebout (2019-04-11 09:41:52 am)

Offline

 

#4 2019-04-11 05:16:38 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 864

Re: InDesign CC 2019 - Find GREP on specific page

Ah. In that case, you have to reference the table's parent—the text frame.

		change grep theDoc's page j's text frames's tables

If you've mixed tables and text inconsistently, then this become slightly more complex; you'll need two different grep statements to handle both classes, and it will probably require a try block to not act when a table isn't encountered.

Offline

 

#5 2019-04-12 11:20:56 am

bebout
Member
From:: San Diego, California
Registered: 2004-11-24
Posts: 18

Re: InDesign CC 2019 - Find GREP on specific page

Thank you Marc, it still gives an error
"every table of every text frame of page 1 of document id 40 doesn’t understand the “find grep” message.", it gives a similar message when using change grep. Any ideas? I really appreciate your help

Offline

 

#6 2019-04-12 05:57:37 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 864

Re: InDesign CC 2019 - Find GREP on specific page

Hi. Your object doesn't understand the command, as it doesn't exist, as I stated would be a pitfall. The error from table non-existence needs to be trapped in a try block (or otherwise avoided). A frame may also not exist, but that's A-okay by InDesign, as an empty list gets returned.


Applescript:

tell application "Adobe InDesign CS3"'s document 1
   repeat with Counter from 1 to count pages
       try
           find grep (page Counter's text frames's tables)
       end try
       find grep (page Counter's text frames)
   end repeat
end tell

Offline

 

#7 2019-04-15 12:05:42 pm

bebout
Member
From:: San Diego, California
Registered: 2004-11-24
Posts: 18

Re: InDesign CC 2019 - Find GREP on specific page

Thank you Marc

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)