Every employee knows how much sticky work is done by inserting captions under graphs (photos, drawings, diagrams) into longer documents teeming with such information. We offer a scenario that greatly facilitates and speeds up this operation. It's simple enough that you can quickly get your bearings and customize it to suit your needs.
In our case, we will add a text frame with the object style ‘caption', which you created in advance, with the content “Caption”. In this style, it is good to specify the distance from the top border and select the "ignore text wrap" option. The last line of the script is grouped graph with text – for us this is a more convenient and flexible solution, but you can safely delete it if you keep the image and text as separate objects.
Copy and save it to a text file with the *extension.The jsx code is attached below, in the folder (for Windows) – C:\Users[user]\AppData\Roaming\Adobe\InDesign\Version 14.0\en_GB\Scripts\Scripts Panel.
You can choose the file name, but we still recommend that it be in Latin, for example, Caption-this is exactly how it will appear in the list of scripts, indesign (ID).
Before running the script, you need to be selected on the graph.
Use health! 🙂
if (app.selection.length == 1 || app.selection[0].constructor.name != "Rectangle")
var myPicture = app.selection[0];
var gb = myPicture.geometricBounds;
// adding a text frame to the label
var myCaption = myPicture. parent. TextFrames. add ( );
/ / define the position and dimensions of the myCaption text frame
.geometricBounds = [gb[2], gb[1], gb [2]+14, gb[3]];
/ / apply a style to the caption text frame object-in the case of" caption "
myCaption.applyObjectStyle (app. ActiveDocument.objectStyles.item ("caption"));
/ / Text
myCaption. contents = "Caption";
/ / dimensions of graphics and text
myPicture.parent.groups.add ([myPicture, myCaption]);