Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

script request

Community Beginner ,
Aug 12, 2022 Aug 12, 2022

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

TOPICS
How to , Scripting
438
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 12, 2022 Aug 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 
...
Translate
Community Expert ,
Aug 12, 2022 Aug 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);

};

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 12, 2022 Aug 12, 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]
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2022 Aug 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2022 Aug 13, 2022

Hi Mark,
Thanks again, it is working better on a small extracted indd of 30 pages. The 1500 pages doc gives this error I don't understand why only in the small doc this error is given: Schermafbeelding 2022-08-13 om 14.09.32.pngexpand image

 

I ment the final percentage of the image should be 110%, when I run the script twice, it is gonna be 121 etc percent. I have set most images by hand on 110% already so I set graphicScalePercent: 100 (works ok).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2022 Aug 13, 2022

I found a corrupted image that coused the error.

thanks for your help !!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2022 Aug 13, 2022

Yes the first script will scale graphic every time you run it. I have changed it now to set the scale of the graphic to an absolute value, eg. 110%. It means that every graphic found would have scale 110%.

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 14, 2022 Aug 14, 2022
LATEST

you saved my week!

keep up the scripting.

Best, Joop

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines