Illustrator Variable Data Exploratory Techniques: Using Actions to Style Overset Text

Illustrator Variable Data Exploratory Techniques: Using Actions to Style Overset Text

As with all Illustrator Variable Data articles, this one deals with exporting dynamic documents from Adobe Illustrator using the Variables feature. To learn how to use variables to output variable documents, see the article on using a script to import a spreadsheet.

Summary

This is an "exploratory technique" and is not recommended for use. This article will explain its construction and describe the observation of how it performed.

The Challenge

When using variable data to change out text, the biggest challenge comes from dealing with overset text which inevitably occurs due to the nature of text which is meant to change. In an earlier article, I have written about using scripts to sense the text overset and size the text down accordingly, which is the best option compared to the one explored here.

The manual methods of solving overset text are to simply style the text such that the biggest amount of characters will still fit into the allotted space and be still visually acceptable. To further tweak the appearance of text which may run out of its preferred space is to use Text Threading, Text Wrap, objects with inverted Text Wrap, auto-size area text option and any possible appearance tricks. Yet, what we most often really want is to have the text not grow out of its preferred bounds, but be shrunk back into them via a reduction in font size or manipulation of other character properties.

In the interest of satisfying personal curiosity, I've explored the idea that actions could be used to actually sense an overset and conditionally size it down. Due to the limitations of Illustrator Actions, one may think it improbable that this issue could be dealt with by just Actions. This is absolutely true, and we are simply lucky that this is even a possibility. After testing my idea, I had some mixed thoughts on the results. It is important to know that this is not a best practice or advice.

Solution: Cascading Overset Management

The basis for this idea is that while many actions which are essential for manipulating art are unsuitable for conditional application, there is one which is able to "fail silently" and allow a fall-through for next steps in action playback. This command is "Select All on Active Artboard", it must be inserted into an action via the "Insert Menu Item" inside the Actions panel flyout menu, and it is located in the "Select" menu item of the application menu bar. When this command plays and nothing is selected because the active artboard has no objects overlapping it, it simply does nothing. It does not interrupt and stop the playback for the rest of the actions, so every following down-the-list action plays.

This is how the actions are tricked into conditionally-selecting an art item

Therefore, an artboard rectangle could be used to create a selection when there's a selectable art object overlapping it. Using a point-text text frame placed a certain distance from such a testing artboard and trying to select the artboard contents repeatedly will select the text frame when its characters cause it to overlap the testing artboard. Immediately following the selection action, a pre-made character style is applied. Such a style would be geared to shrink the text back to the preferred bounds by changing any number of attributes in the character style such as font size, tracking, and more. This style could also use different colors and stroke attributes, should there be a case where text of different sizes can benefit from colored differently. If the textframe shrinks enough to get off the bounds of the artboard, the next time the selection action is invoked to select all on active artboard, it will no longer be selected. However, if it remains selected, it will be subsequently styled with the next character style meant to reduce its width even smaller. With a multiple number of styles meticulously created in a document, it is actually possible to make a robust overset styling mechanism.

The "cascade" in this technique refers to how all of the action will be processed for each time it runs: if the textframe shrinks enough to be no longer selected, the rest of the styles will be "clicked-on" by the action, regardless of where it should have stopped if it was smarter. The fact that it works without any complaint on behalf of the action when a character style is applied without a selected art object is another essential component in making it possible.

Creating the action which selects, styles and exports the styled file is described below.

Actions Intro

When it comes to making a UI-centric part of the creative or production graphic process more efficient, often the first method considered is the Actions functionality of Illustrator, which allows a recording and playback of some application events such as moving an object, saving a document, etc. Actions are not suited to perform complex and conditional tasks, unlike scripts or software, because they do not employ any conditional logic and many of the recordable actions come with a "convenient" fail-fail mechanism that stops the flow of the playback to tell the user that an action failed and playback is aborted.
For example, one would think that a recorded form of "Deselect All" (Cmd+Shift+A) would simply do nothing in the playback if there was no item selected to begin with. However, it complains and stops the playback as it is considered a grave error by the action mechanism. To workaround this, I made an action to "Safe Deselect" which works by first drawing a shape, which loses any previously selected art and only leaves this new shape selected, and then, I use a "Clear" command (record the delete key on an art selection) to delete the shape. This act leaves the document without a selection.

Luckily, the "Select All on Active Artboard" menu item allows the playback to continue even without the presence of a selection. This is a subtle means to having the actions employ logic: a procedure could be applied to a selection and safely bypassed when there is not a selection.

When crafting the actions, which can be a long and frustrating process, it helps to make actions which are saved in such a way that repetitive blocks can be re-used by calling the action they are saved in. To play another action within your action, use the Action panel's play button while the first action is recording. This way, entire blocks can be re-used. Yet in the time and effort it takes to whip this up, it would be a really slippery slope to instead write a quick javascript to accomplish this easier, much more powerfully, and with a higher chance of it working. (Recording the Rectangle tool was quite unreliable as it would draw not where I wanted it to in playback. Use "Insert Select Path" instead.)

These are the actions I've created inside of a set called "Cascading Overflow Management". 

  • Safe Deselect just draws a circle and clears it, de-selecting all document selection in the process.
  • Reset Default Styles makes sure that each document starts with the default style, which would be the largest possible size. It uses the "Select Object whose note contains..." item of the Action Panel's flyout menu to select the appropriate textframe to be styled back to the specific default style.
  • Overflow Test Action: test_frame applies the character styles intended for the textbox which I've noted (in the attributes/note feature) to have a note "test_frame" for personal reference.
  • Overflow Test Action: title applies the character styles intended for the textbox which I've noted to have a note "title" for personal reference.
  • Master Overflow Action combines the various actions in a procedural process, first deselecting any current selection, then applying the character styles for both textframes, exporting the first artboard to a destination file, and then finally resetting the default style back to the defaults.

Making an Artboard Change its Location

Using a single testing artboard can work for one text frame, but it would be nice to have control over multiple text frames in a document. In order to style multiple different text frames with different styles with this method, it is necessary to have a couple such artboards which test for overlapping text - but unfortunately in the world of Actions, traversing artboards does not seem possible. However, it is possible to move a rectangle path around and to size a single artboard to it using the "Fit to Selected Art" command. Therefore, moving and fitting to a rectangle is just enough of the function we need for this technique to work. Once the text styling for one artboard is done, the next styling action will move the active artboard to its text frame's horizontal level.

It is important to note that playing this action alone or in batch process means having to start with the smaller artboard active. Otherwise the main artboard will be used to fit to testing rectangles and the main export picture will come from the tiny testing artboard bounds area instead.

The Batch Process

This is my screen of the settings used for the batch processing of the variables.

Its source is Data Sets, the Override Export checkbox sends the output to a custom destination, and the output file name is set to data set name. Illustrator has a funny problem not adding the file extensions to the output file name, so when using Save As commands such as "Save as PDF", the workaround has been to use "Save a Copy" instead, which places the correct file extension. For my export of one artboard range using the Export PNG output method, there is no Save a Copy, and the extension gets left right off. I even tried to add ".png" to the dataset names, but it was mysteriously stripped from the resulting file name. Also, as this was the first artboard, the text "-01" was automatically added to my extension-less resulting file names.

To rename the files to have the correct extension, an extra process has to be used such as any automatic utility which can accomplish this, such as Automator on Mac, or some folder-actions.

The Document

On my example document, it is a single badge graphic with two textframes. Both of them are affected by the overset styling Action. During processing, an artboard is repeatedly tested for selectable items, and as long as an encroaching text frame is found, the style is applied to it. However, if we are using the actual textframe which will be located in the artboard to test the length of the character string, it will give us problems because other art may be selected, and there would likely be an artboard inside of another artboard. To make sure this is not a problem, I've placed the textframes above the main artboard, in the pasteboard area, and used a transform effect to duplicate their appearances below unto their landing zone inside the main artwork.

There is an extra tiny artboard, to help with styling more than one text frame.
Last but not least, there are Character Styles in the document which are native to documents in Illustrator, meaning you can save and load them from other .ai files. The "saving" part is curiously absent from the Character Styles flyout menu, the implication being that the current document is the library.

The Character Styles

The driving force behind this practice is how character styles can be applied by an action to specific art of choice. Simply have the right item selected, and the character style will be applied. If there is no selection, the button is pushed, but nothing bad happens.


There are 2 default styles, one for each of the textframes in this template, and 3 size-down styles for each as well. When the textframe is selected, all of the styles will be applied until the textframe is too small to be selected on the next pass, in which case the selection and styling actions will play all the way down the list with no consequence.

The Data

I've just scrapped together a list of fictitious names and titles, selecting a variety of character lengths that would fit into my template as the smallest style. 

Result

What an exciting experiment. I used the Export .PNG option to export the first artboard into my destination series of .png files named to their datasets I've picked for them using the VariableImporter.jsx dataset name assigner. Exporting in a format that lets just one of the artboards be saved is important to this process.

After having run is successfully for a number of times, I have come to the conclusion that this is hardly a legitimate solution compared to the ones offered by scripting or plugins. 

It took several runs and revisions to get the best fit and the final iteration of the desired look reflected in the latest character styles within my template. Luckily, this is not too long of a process for just 2 text frames, as the Character Styles panel allows quick alteration of a style with the "Redefine Character Style" menu item in its flyout menu.

Early test with unacceptable styling

Each style was tweaked following the initial result to provide better appearance.

Final result 1st variation

Finally, I wanted to change the style of the title field to be in Small Caps, so I redefined each of the styles associated with this textframe to include the Small Caps. This can be done by clicking on each style in the Character Styles panel, using the Character panel to set the Small Caps, and clicking Redefine Character Style in the Character Styles panel's flyout menu. Alternatively, the character style can be double-clicked in the Character Styles panel to open up a modal dialog which allows setting the Small Caps inside it, and changes the style when dismissed with "Ok".

Final result 2nd variation

Conclusion

The effort that takes into using this method is more than writing a little javascript to take care of this issue.  With scripting, you can exert a much more powerful control over the entire process. However, the ability of the textframes to be styled with pre-recorded Character Styles could also be used via a script. Using character styles adds a great amount of versatility to styling point text to fit certain bounds, that having a robust set of 8 - 10 such down-size styles could be useful. As character styles can be loaded and referenced by name in actions, the actions and styles can be separated and made versatile by the use of generic names and a same style structure for different documents.

Also, since character styles can be anything you want, the extra-small textframes could be styles with a huge font and an obnoxious fill color to signify a bad instance of overset text for easy-detection in a preview set.

Besides the issues and the effort involved in the creation of this technique, the real deal-breaker is the abominably slow speed at which the batch process runs. Due to playing every style to apply and each artboard fitting, multiple times per run, processing each file with just 2 textframes took longer than could be acceptable in a high-pace environment with just 10 records. Additionally, Actions are really awesome about pausing any process when the application screen is not in the front: think of it as opposite of running in the background even for the simplest of tasks.

My general findings are that while using this Action approach is non-viable, the use of Character Styles could be of use in conjunction with scripts when managing overset text. 

Other Data-Appearance Transfer

There are some tantalizing possibilities from this technique to be used in different setting though. For example, here is a possibility of using this same method with a single artboard area in conjunction with a set of text frames which could contain expected lengths of characters. Generic characters such as dashes could be used. (--------------------) Using the conditional selection via artboard, mutiple objects can be selected using the "Select Same" commands to select items with the same graphic style as the testing text frame. Then a graphic style of a certain name could be applied. This way, a length of characters in a spreadsheet cell could decide appearance attributes such as rotation angle for a line. Even though that's an idea, the slow speed of action playback should be considered.

To view or add a comment, sign in

More articles by Vasily Hall

Others also viewed

Explore content categories