Hi @joop25628618fwiu, I wrote a similar script recently so it was easy to adapt to your request. Let me know if it works for you. I have commented the script so hopefully you can follow along what it is doing.
- Mark
/**
* Performs sizing, scaling and
* content-fitting on first rectangle
* on every left-hand page.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/script-request/m-p/13131713
*/
function main() {
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var mm = 2.83465,
// the adjustments:
settings = {
newFrameBounds: [-3 * mm, -3 * mm, 233 * mm, 150 * mm],
graphicScalePercent: 110,
}
if (app.documents.length == 0) {
alert('Please open a document and try again.');
return;
}
var doc = app.activeDocument,
spreads = doc.spreads,
counter = 0;
// check through all spreads
for (var i = 0; i < spreads.length; i++) {
// we only want spreads with 2 pages
if (spreads[i].pages.length == 2)
// if it has a rectangle
// and it has a graphic
if (
spreads[i].pages[0].rectangles[0].isValid
&& spreads[i].pages[0].rectangles[0].hasOwnProperty('graphics')
&& spreads[i].pages[0].rectangles[0].graphics.length > 0
&& spreads[i].pages[0].rectangles[0].graphics[0].isValid
) {
// perform the adjustments
adjustFrame(spreads[i].pages[0].rectangles[0], settings.newFrameBounds, settings.graphicScalePercent, true);
counter++;
}
}
// finished
alert('Adjusted ' + counter + ' graphics frames.');
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Adjust LHS graphic");
/**
* Sets a graphic frame's bounds
* and scales and centers graphic.
* @param {Rectangle} frame - an Indesign Rectangle.
* @param {Array} bounds - the new bounds [T, L, B, R].
* @param {Number} scale - the graphic scale percentage.
* @param {Boolean} absoluteScale - whether scalePercent is absolute or relative.
*/
function adjustFrame(frame, bounds, scale, absoluteScale) {
if (bounds != undefined)
frame.geometricBounds = bounds;
var graphic = frame.graphics[0];
if (scale != undefined)
if (absoluteScale) {
graphic.absoluteHorizontalScale = scale;
graphic.absoluteVerticalScale = scale;
}
else {
graphic.resize(
BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS,
AnchorPoint.BOTTOM_LEFT_ANCHOR,
ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY,
[scale / 100, scale / 100]
);
}
graphic.fit(FitOptions.CENTER_CONTENT);
};