Sunday, June 16, 2019

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

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

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: 873

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: 19

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: 873

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: 19

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: 873

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: 19

Re: InDesign CC 2019 - Find GREP on specific page

Thank you Marc

Offline

 

#8 2019-04-24 10:33:16 am

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

Re: InDesign CC 2019 - Find GREP on specific page

Duplicating each page of the documents to a temp document to GREP is the solution that I've gone with. Here's my final code for anyone else trying to do something similar. Thanks again Marc for your help.

Applescript:

set niceList to {}
set finalList to {}
global x, finalList
set AppleScript's text item delimiters to ""



set theFolder to choose folder with prompt "Please select a folder of InDesign files to process."
set theFiles to list folder theFolder without invisibles

set fileCount to 0

set theFiles to my simple_sort(theFiles)

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 find text preferences to nothing
   
   set case sensitive of find change text options to false
   set include footnotes of find change text options to false
   set include hidden layers of find change text options to false
   set include locked layers for find of find change text options to false
   set include locked stories for find of find change text options to false
   set include master pages of find change text options to false
   set whole word of find change text options to false
   
   tell script preferences
       set user interaction level to never interact
   end tell
end tell

repeat with x in theFiles
   
   
   set thisFile to theFolder & x as string
   
   if thisFile ends with ".indd" then
       
       set fileCount to (fileCount + 1)
       
       tell application "Adobe InDesign CC 2019"
           
           with timeout of 9999999 seconds
               open thisFile
           end timeout
           
           set theDoc to the active document
           set pageList to {}
           set thePages to ""
           set keepGoing to false
           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 x from 1 to count of pageList
                   tell application "Adobe InDesign CC 2019"
                       set tempDoc to make new document
                   end tell
                   try
                       duplicate every page item of item x of thePages to page 1 of tempDoc
                       set keepGoing to true
                   on error
                       set end of finalList to "?" & "," & (item x of pageList as string)
                   end try
                   if keepGoing is true then
                       tell application "Adobe InDesign CC 2019"
                           with timeout of 9999999 seconds

                           set find what of find grep preferences to "\\d{6}"
                           
                           tell tempDoc
                               set testList to ""
                               set testList to find grep
                               
                               repeat with i in testList
                                   set thisSet to ((text of i as string) & "," & (item x of pageList as string))
                                   if finalList does not contain thisSet then
                                       set end of finalList to thisSet
                                   end if
                               end repeat
                               close tempDoc saving no
                               delay 10
                           end tell
                       end tell
                   end if
               end repeat
               close theDoc saving no
           end tell
       end tell
   end if
end repeat

set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {","}}
tell application "Microsoft Excel"
   activate
   with timeout of 600 seconds
       set theBook to make new workbook
   end timeout
   set value of cell "A1" to "Part Numbers"
   set value of cell "B1" to "Page Number"
   set theSheet to active sheet of theBook
   set usedRange to used range of theSheet
   set rCount to count of rows of usedRange
   set rCount to (rCount + 1)
   repeat with i from 1 to (count of finalList)
       try
           set value of cell ("A" & (rCount as string)) to (text item 1 of item i of finalList) as string
           set value of cell ("B" & (rCount as string)) to (text item 2 of item i of finalList) as string
           set rCount to (rCount + 1)
       end try
   end repeat
end tell
set AppleScript's text item delimiters to saveTID


on simple_sort(my_list)
   set the index_list to {}
   set the sorted_list to {}
   repeat (the number of items in my_list) times
       set the low_item to ""
       repeat with i from 1 to (number of items in my_list)
           if i is not in the index_list then
               set this_item to item i of my_list as text
               if the low_item is "" then
                   set the low_item to this_item
                   set the low_item_index to i
               else if this_item comes before the low_item then
                   set the low_item to this_item
                   set the low_item_index to i
               end if
           end if
       end repeat
       set the end of sorted_list to the low_item
       set the end of the index_list to the low_item_index
   end repeat
   return the sorted_list
end simple_sort

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)