GREP to Anchored Object

Using “GREP to Anchored Object”

Introduction

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:

  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.

These steps will be described below.

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:

Grep to Anchored Object Options Screen

 

  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 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.
  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. 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.
  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 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!)

Questions? Comments?

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

Article Comments
  1. mayerMarch 21, 2018 11:14 pm
    Reply

    Hi
    i have anchored-text box on top of each word and i would like to center it on every word
    is it possible to have a script to center each anchored-text box on top of a word

    • ArielJanuary 7, 2019 12:05 pm
      Reply

      It could be done, but would need a custom modification to get the word centred in relation to another word.
      However, I would advise against a setup like this, because having so many anchored objects will slow InDesign to a crawl. A better solution would be to set up a parallel text frame, not anchored, and add the translations in the correct places, avoiding dozens of anchored objects per page.

  2. seongjae weonSeptember 17, 2018 6:26 pm
    Reply

    I tried to find grep in the text box and make it a “Grep to Anchored Object” I bought here.
    But it did not work.
    I am wondering how to create an anchored object exactly where the text box is located.
    If you can not achieve “Grep to Anchored Object”, I would like to know if you can provide a script to solve it.

    Best Regards,

    • ArielSeptember 17, 2018 7:43 pm
      Reply

      Hi,
      Send me an email to admin [at] id-extras.com and I’ll be happy to try and help create the right GREP expression to get the script working as needed!
      Thanks,
      Ariel

  3. Daniela WeilandDecember 6, 2018 2:21 pm
    Reply

    I tried the script and it works fine. But is there also a possibility to copy the text only and don’t delete it?

    Best regards
    Daniela

    • ArielDecember 8, 2018 11:02 pm
      Reply

      Hi Daniela,

      There is not a built-in way to do that. The text is moved into the anchored object and deleted from the main document.
      However, it should be fairly easy to duplicate the text first with a GREP find/change. At the same time you could apply a new colour to the copied text (or something like that). Then run GREP to Anchored Object only on text with the other colour.
      That way you will be left with a copy of the text in the main document as well…
      I could also customize the script to add this feature — get in touch if you would like a quote for that.

  4. Kevin CallahanFebruary 1, 2019 9:39 pm
    Reply

    Hi, this looks like it could be a great help in preparing a document for epub export. Anchoring sidebars and other asides can be a pain in the neck, depending on how the InDesign user set up the document.

    Often, a sidebar will have a headline/title and then some paragraphs, so there could be at least 2 paragraph styles, sometimes more (if there’s also a bulleted list, for example). Can this script grab more than one paragraph style, extract them all, and place in an anchored text box? would be fabulous…..

  5. ArielFebruary 3, 2019 2:42 am
    Reply

    Hi Kevin,
    Sure it can, but with a little help, since it’s not possible to search for 2 paragraph styles at once with a single GREP search.
    What you could do, though, is, for example, apply a special color to the text of all the paragraphs you want the script to pick up.
    Then, set up the GREP search to search for that color, rather than for specific paragraph styles.
    Does that make sense?
    Ariel

  6. PeterJanuary 22, 2020 9:38 am
    Reply

    Hello,
    Thanks for your script, very useful!
    Do you develop reverse writing?
    For example:
    1: paragraph with “Para Style 1” to Anchored (your script)
    2: Anchored to initial position “Para style 1” (futur script ?)
    Thank you for your reply,

    Peter

  7. MauserOctober 27, 2020 1:19 pm
    Reply

    Anchored Object feature of the ones
    batch cancel , how can it be done
    thanks

    • ArielOctober 27, 2020 9:40 pm
      Reply

      Hi Mauser,
      I don’t really understand the question.
      But if you’re looking to move a bunch of anchored objects back into the main text flow, check this out: Anchored Text Uncaged

Leave a Comment