Using “GREP to Anchored Object”
Grep to Anchored Object is a useful InDesign script that makes it easy to extract any text in your document out of the main flow of the text and into an anchored object. The anchored object will be anchored to the original location of the text.
What are anchored objects?
An anchored object is any page item (such as a graphic, or, in our case, a text frame) that is linked (or “anchored”) to text. If the text moves, the anchored object travels with it.
Anchored objects have many settings, mainly relating to where on the page the anchored object should appear. They can flow directly with the text, or always appear on a fixed point on the page relative to the text, and much more.
It is beyond the scope of this guide to explain in detail all the options available for anchored objects – more information about them is available here: https://helpx.adobe.com/indesign/using/anchored-objects.html.
Before running the script
Two preparatory steps are required before running Grep to Anchored Object:
- Create a GREP query that will find the text you wish to extract and place in the anchored object.
- Create an object style for the anchored objects the script creates.
These steps will be described below.
STEP 1: Creating a GREP query
- Open InDesign’s Find/Change dialog and click on the GREP tab:
- Set up your GREP query as you like: You can search for specific text, or just a paragraph or character style, or any text with special formatting, and so on. The possibilities are endless.
- GREP to Anchored Object optionally can be set to perform a “Change GREP” on the text it extracts and places into the anchored objects. If you would like to use this option, set up the “Change to:” options as needed.
STEP 2: Creating an object style
If you have not already done so, create an object style that the script will use for the anchored objects it created.
Using the object style’s “Anchored Object Options” set the position and style of the anchored object you wish to create.
You are now ready to run the script.
GREP to Anchored Object settings
Here’s a screenshot of the GREP to Anchored Object window:
- Anchored object style: This dropdown menu will list all the object styles in the current document. Select the object style to use for the anchored objects that will be created. The way the selected object style is set up will make a big difference to the way the pages will look after the anchored objects are created. But of course, you can always change the object settings after running the script as well!
- Width: Type in the preferred width you would like each anchored object to be given. This is not something that can be set easily as part of an object style. The desired width must be entered in millimetres only.
- GREP options: GREP to Anchored Object will extract your text and place it in an anchored object. If you select this option, it will then perform a “change GREP” operation (based on InDesign’s current “change GREP” settings) on the text inside the anchored object it has created.
- Location options: By default, the objects created by the script will be anchored to the exact same place as the original text. However, two additional options allow you to link the object to the end of the previous paragraph (the paragraph before the paragraph in which the found text is), or to the start of the paragraph in which the found text is.
- Scope: Here you can select whether the script should extract text only from the current selection, the current story, or from the entire document. To use the “Current selection” option, select some text before running the script. To use the “Current story” option, select some text or a text frame before running the script.
- OK Button: Click OK to run the script based on the settings chosen. All text found (based on InDesign’s current “find GREP” settings) will be extracted from the main text flow and placed into an anchored object to which will be applied the selected object style. If selected, a “change GREP” operation will also be performed on the text in each of the newly created anchored objects.
- Cancel button: Close the window and exit without doing anything.
- About button: Opens a new window which shows the current script version, provides an option to add this script to the optional Id-Extras menu, and also includes links to this page, the EULA, and the Id-Extras.com products page.
All settings you make are stored with the document for convenience so they needn’t be reentered every time the script is run. Also, even if you need to edit the document several months later and re-run the script, the old settings should still be there. (This does not affect document portability – so someone who does not have GREP to Anchored Object will still be able to open and edit the document without seeing a “missing plug-in” alert!)
Please feel free to write your questions or comments about Grep to Anchored Object below.