Copy link to clipboard
Copied
Thanks to FRIdNGE, the great original script provider!
There's also Robert at ID-Tasker who has been quite helpful.
It is now suitable for the case of one caption for one picture, allowing the caption to be quickly pasted close to the picture.
The original post seems to have sunk.
I'm trying to modify it to a situation where multiple images share a caption, but I don't know how to traverse out the textframe and image with a loop.
/*
_FRIdNGE-0766_ImageCaptionAlignment.jsx
Script written by FRIdNGE, Michel Allio [02/11/2024]
*/
//https://community.adobe.com/t5/indesign-discussions/script-to-match-object-sizes-and-align-captions-in-indesign/m-p/14941759
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, 'Image And Caption Alignment');
function main() {
var myDoc = app.activeDocument;
var myRulerOrigin = myDoc.viewPreferences.rulerOrigin;
if ( app.selection.length != 2 ) {
alert( "Select 2 items!")
exit();
} else {
if ( app.selection[0] instanceof Rectangle && app.selection[1] instanceof TextFrame ) {
var myGraphicFrame = app.selection[0];
var myTextFrame = app.selection[1];
} else if ( app.selection[1] instanceof Rectangle && app.selection[0] instanceof TextFrame ) {
var myGraphicFrame = app.selection[1];
var myTextFrame = app.selection[0];
} else {
alert( "Bad Selection!")
exit();
}
myDoc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
myTextFrame.geometricBounds = [ myGraphicFrame.geometricBounds[2], myGraphicFrame.geometricBounds[1], myGraphicFrame.geometricBounds[2] + myTextFrame.geometricBounds[2] - myTextFrame.geometricBounds[0], myGraphicFrame.geometricBounds[3] ];
myDoc.viewPreferences.rulerOrigin = myRulerOrigin;
}
}
Hi @dublove, here is one approach...
- Mark
/**
* @file Align Caption Frame To Graphic Frames.js
*
* Usage:
* 1. Select the caption, a text frame
* 2. Also select one or more graphic frames
* 3. Run script
*
* Script will align the left and right edges of the caption frame
* to the left and right extremes of the graphic frame(s), and
* also align the caption frame above or below the graphic frame(s).
*
* @author m1b
* @version 2025-04-23
* @discussion https://community.adob...
Copy link to clipboard
Copied
But I tried another newly created document and it has 17mm more
For some reason, it's in the example document I passed along.
You regenerate the title note and it's just properly aligned.
Turns out that text box has a ghost ......
Copy link to clipboard
Copied
Press Alt+click none to clear the optimization and then align it again and it's normal
But after half a day of looking it up, I still haven't figured out what's causing the irregularity.
Copy link to clipboard
Copied
I found the reason:
The script does not support inner margins.
Adding inner margins will result in no alignment.
But I need the inner margin feature. It's really sad.
Copy link to clipboard
Copied
Hi @dublove I found a bug where Indesign wasn't respecting my geometric bounds because I made them too small in some cases. I have fixed this now. Also I added a settings property `adjustForTextFrameInsets` which will adjust the frame to account for the text frame insets. Try it with this true and false to see how it works:
Also use `gap` if you need to.
- Mark
Copy link to clipboard
Copied
Left-right alignment is OK, but the textbox ignores the upper "Inner Margin" setting.
The "Inner Margin" setting in the object style should be retained.
Left-right alignment is OK, but the textbox ignores the upper “inner distance” setting.
The "Inside Distance' setting in the object style should be retained.
Also, can you get the GraphicFrame.geometricBounds[2] of a particular image?
Wouldn't that solve the case where the text box appears above the image?
Copy link to clipboard
Copied
I have added finer control over which text frame insets are used, so I have set it to [false, true, false, true] so that only left and right insets are used.
Also I fixed one more bug that caused a problem in some cases when the text frame was above the graphics.
- Mark
Copy link to clipboard
Copied
It's OK.
Saves so much work, it's great.
Another big step forward for Adobe.
I thank you for all the people in the world.
Copy link to clipboard
Copied
You're welcome!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more