Adobe Illustrator: Batch replacing objects

[et_pb_section fb_built=”1″ _builder_version=”3.0.47″][et_pb_row _builder_version=”3.0.47″ background_size=”initial” background_position=”top_left” background_repeat=”repeat”][et_pb_column type=”4_4″ _builder_version=”3.0.47″ parallax=”off” parallax_method=”on”][et_pb_text _builder_version=”3.0.47″ background_size=”initial” background_position=”top_left” background_repeat=”repeat”]

In Illustrator (CC 2017) there is no Find-and-Replace for objects and batch substitution of objects is not possible.  For most illustrations this is a non-problem because Illustrator supports Symbols (and recently Dynamic Symbols); editing the base symbol propagates changes through all instances.  However, this requires that the objects were to be created as Symbols, and naïve objects are forever barred from this method.

Naïve objects, however, is sometimes what we need to work with.  Sometimes we work with files passed down to us; in my case, I was working with SVGs generated programmatically (by P5 / P5.svg).

I could find two attempts to get over this problem, one by JET on Adobe Forums, and one by Loic Aigon on Scriptopedia.  Both makes use of scripts.  JET’s method is more general, allowing the choice of any symbol in the list instead of one named “Dot”.

JET’s script was 90% what I needed, but it simply sizes replacement symbols to the same height as the objects-to-be-replaced, and I wanted additionally rotation and opacity to be preserved.  Here I present my extension that preserve opacity and (conditionally) rotation: you can download the script here.  An example of what it does is shown below, along with a comparison with JET’s original effect.  The original symbols are duplicated for you to see the effect.

Demo of scripted object replacements
Demo of scripted object replacements

To use this script, first select the objects you want to replace.  If there are too many, consider the options you have available under the Select menu.  Second, use the script by going to File -> Scripts -> choose file.  A pop-up box appears.  Enter the number of the symbol you wish to replace the objects with (top in your listing is 1).

You should note two gotchas in using this script:

  1. The most important one is that Illustrator does not keep information about rotation: from the object’s perspective it does not know there is such a thing as “right way around”.  To work around the rotation I constructed this data from the nodes, and in doing so it assumes something of the geometry.  My extension is designed for objects in which the first and last nodes designate the rotation: straight lines and rectangles work great.  The script behaves strangely for other objects, as you can see from the ellipses.
  2. The object and its replacement are aligned on its left and top, and not the center.  This may give the sense that the replacement has been erroneously moved at certain rotations (see the rectangle comparisons).



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

zh_HKChinese en_USEnglish