GREP to Anchored Object

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:

Before running the script

Two preparatory steps are required before running Grep to Anchored Object:

  1. Create a GREP query that will find the text you wish to extract and place in the anchored object.
  2. Create an object style for the anchored objects the script creates.

STEP 1: Creating a GREP query

  1. Open InDesign’s Find/Change dialog and click on the GREP tab:

  1. 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.
  2. 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:

  1. 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!
  2. 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.
  3. 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.
  4. Location options: By default, the objects created by the script will be anchored to the exact sample place as the original text. However, it can sometimes be useful (especially when the text is at the start of a paragraph, or indeed is a complete paragraph on its own) to anchored the object to end of the previous paragraph rather than to the start of the following paragraph. This is where to set that option.
  5. Scope: Here you can select whether the script should extract text only from the current selection, the current story, or from the entire document.
  6. 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.
  7. Cancel button: Close the window and exit without doing anything.
  8. 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 products page.

Questions? Comments?

Please feel free to write your questions or comments about Grep to Anchored Object below.

Leave a Reply