Creating Text Frames for Image Captions

Here is a series of scripts which accomplish the simple task of creating a caption frame for images. You can either do frames one-by-one, or select a number of frames as long as you want the captions in the same position relative to the image.

I tend to prefer simple scripts, with little or no input needed, which is why I made individual scripts for each position, but at the bottom, I'll show how to create one script which needs input to state which position to place the caption. The sizes and positions of frames can be changed according to your needs, and like any frame, can be edited afterward. Your page units don't matter, since the script converts to points and uses points, then switches back again.

In usage, this would be a situation where you could save time be creating a caption Paragraph Style for the caption frames. One thing to notice is that the scripts do not check for object type, so you can create "captions" for any object, such as shapes, text frames, render frames, vector graphics, or even groups of objects (make sure you actually group them, since if you just select a number of objects, each one will get its own caption).



caption.py
Here is one more script which incorporates all the above options, by allowing you to choose position in a dialog. If you enter something other than b/t/r/l it shouldn't do anything. This script is now included with versions 1.4.7svn and 1.5.3svn as Caption.py.

Additional mods
In case you would like to set the width and height of the right and left captions, you might add the possibility of entering values. I'm going to use a single valueDialog for this, then use the python .split operator. Here is the original script section:

Let's change it to this by adding four lines, and use the variables instead of numbers in the createText command: Remember that everything entered into a valueDialog is a string, so after splitting to 2 separate values, we then need to convert to float since this is what createText requires. Add the extra lines for the left caption also to complete the process, but note that it's a bit trickier, since the upper left corner of the caption frame depends on its width and height.

Adding a caption style
Here is another modification to the bcaption.py script – let's call it bcaption_style.py. We add 2 things here – one is to create a caption Paragraph Style. I chose a Liberation Serif Italic font at 10 pts. First we need to check to make sure there already isn't a style named Caption, and if not, it's created. It is then used to show the name of the frames that are created, simply for an example of its appearance. The other thing is to create a small Top Distance for the frame, so that the text isn't right up against the bottom of the frame.