Skip to main content
gplumblee
Known Participant
October 18, 2023
Answered

Enlarge Graphic Frame Slightly After Fitting Frame to Image

  • October 18, 2023
  • 3 replies
  • 1760 views

Hi Community,

I'm doing a piano method book with hundreds of music imports that fit to bounding box when imported (so imports won't overlap. These PDFs are made up of vectors and fonts. There are times when a font gets cut out of the frame by a hair, and I want to find a quick way to select all graphic imports and enlarge the frame lightly without enlarging the music import. I tried setting the Frame Fitting Options to crop at -1 pt, but that reduces the image rather than enlarging the frame. Is there a plug-in that will help or do you have any other suggestions for me. These books are 112-pages each with 4–8 music imports per page. Thanks!

This topic has been closed for replies.
Correct answer m1b

Hi @gplumblee, here is a quick script that may help. It will expand all graphics rectangles in document by 1 point on each side. Let me know if it works in your case. You can change the expansion by editing the "margin" variable declaration.

- Mark

 

/**
 * Expand Graphics Rectangles By Margin.js
 * This will expand *all rectangles that contain graphics*
 * in the active document by 1 point on every side.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/enlarge-graphic-frame-slightly-after-fitting-frame-to-image/m-p/14168151
 */
function main() {

    // expand frames by this amount (in points)
    var margin = 1;

    var doc = app.activeDocument,
        frames = doc.rectangles;

    for (var i = 0; i < frames.length; i++) {

        if (
            !frames[i].hasOwnProperty('allGraphics')
            || frames[i].allGraphics.length == 0
        )
            continue;

        var b = frames[i].geometricBounds;

        frames[i].geometricBounds = [
            b[0] - margin,
            b[1] - margin,
            b[2] + margin,
            b[3] + margin,
        ];

    }

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Expand Graphics Rectangles');

 

3 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
October 18, 2023

Hi @gplumblee, here is a quick script that may help. It will expand all graphics rectangles in document by 1 point on each side. Let me know if it works in your case. You can change the expansion by editing the "margin" variable declaration.

- Mark

 

/**
 * Expand Graphics Rectangles By Margin.js
 * This will expand *all rectangles that contain graphics*
 * in the active document by 1 point on every side.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/enlarge-graphic-frame-slightly-after-fitting-frame-to-image/m-p/14168151
 */
function main() {

    // expand frames by this amount (in points)
    var margin = 1;

    var doc = app.activeDocument,
        frames = doc.rectangles;

    for (var i = 0; i < frames.length; i++) {

        if (
            !frames[i].hasOwnProperty('allGraphics')
            || frames[i].allGraphics.length == 0
        )
            continue;

        var b = frames[i].geometricBounds;

        frames[i].geometricBounds = [
            b[0] - margin,
            b[1] - margin,
            b[2] + margin,
            b[3] + margin,
        ];

    }

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Expand Graphics Rectangles');

 

Robert at ID-Tasker
Legend
October 18, 2023

@m1b, nice piece of code - as always.

 

Quick question, if I may... 

 

Why do you check for both:

 

!frames[i].hasOwnProperty('allGraphics')
|| frames[i].allGraphics.length == 0

 

Why not just checking the length? 

Every rectangle have allGraphics collection - even empty? 

For me it's "doesn't have allGraphics collection OR no graphics inside". 

Or it works differently in JS? 

 

m1b
Community Expert
Community Expert
October 18, 2023

Two reasons, neither particularly compelling:

(1) I'm not confident in my knowledge of the different types of "Rectangles" in Indesign, although you are probably right that it is safe to exclude the check for "allGraphics", and

(2) when I was writing the script I orginally wrote it to work with selected items, so the check was necessary. When I changed it to suit the OPs situation, the check might not be necessary anymore.

- Mark

BobLevine
Community Expert
Community Expert
October 18, 2023

Sorry, I posted that too quickly. I didn't notice you wanted the frame to expand. Nothing you do is going to change the size of the frame. If they were all the same size you could create that object style and change the size there.

BobLevine
Community Expert
Community Expert
October 18, 2023

Object>Fitting>Frame fitting options. Use negative crops. Save it as an object style.

 

gplumblee
gplumbleeAuthor
Known Participant
October 18, 2023
Thank you BobLevine. This is what I tried before posting: "I tried setting the Frame Fitting Options to crop at -1 pt, but that reduces the image rather than enlarging the frame. "
I think this does work for newly imported graphics, but if correction change the size of the graphic, the setting will shrink the graphic instead of expanding the graphic frame.