Skip to main content
New Participant
August 12, 2022
Answered

script request

  • August 12, 2022
  • 1 reply
  • 638 views

I am resizing a book with on the left (even) pages an imageframe (with the jpg of the old format) that needs to be resized to (in mm)

x = -3

y = -3

width = 153 mm 

hight = 236 mm

image scaled (both horizotal and vertical) to 110%

jpeg positioned in centre of the frame. 

I cannot find a script that I can modify to these dimensions. as it is 500 + images I am very greatfull fo any help on getting a script that would do this trick.

Best, Joop

This topic has been closed for replies.
Correct answer m1b

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);

};

 

 

1 reply

m1b
m1bCorrect answer
Braniac
August 12, 2022

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);

};

 

 

New Participant
August 13, 2022
Dear Mark,

Scripts are new for me, but I managed to make an AppleScript with your codes.
I get an error in script editor, and when used in Indesign another one.
Any clue on what I do wrong?

Joop Steenkamer jr

[cid:89f7a846-eba4-4345-93ab-983857dd1fe0@tudelft.nl]
[cid:df76d303-18ee-424e-8840-a29421003f5c@tudelft.nl]
m1b
Braniac
August 13, 2022

Hi Joop, you're confusing me. Why would you convert it to applescript? Did you try running the script as is? See instructions. Save it as a plain text file with a ".js" extension, and put it in the Scripts Panel folder. A quick way to locate the Scripts Panel folder is to right-click or control-click a script in the Scripts panel, and choose Reveal In Finder.

Then open your document and run the script from the Scripts panel.

- Mark