Skip to main content
Known Participant
November 6, 2024
Question

Script to copy selected object frame/s and create new file/s at object frame size in Indesign

  • November 6, 2024
  • 2 replies
  • 825 views

I'm hoping there's a script for this one but I can't find it after Google searching.

 

I have an object frame on a page and need to copy and paste it into a new file but the new file needs to resize itself to the exact size of the object frame being copied. This will save time in checking measurements for multiple object frames. One at a time is great, but the abilitiy to select multiple object frames at once and it creates multiple Indesign files for each object frame at their respective exact sizes would be even better.

 

The new pages need to have 3 mm bleed added to the page. If it can also add 3 mm bleed to the object frame as part of the same script even better. But Robert at ID-Tasker has already helped me with this amazing script "Resize height and width of multiple sized objects by adding the same measurement to each object" which I can use after it's created the new page file with the framed object.

 

After bleed and fitting image to frame and naming/saving I'd then export each file as a PDF with crop marks and with a particular colour print setting.

 

Many thanks in advance for pointing me in the right direction.

This topic has been closed for replies.

2 replies

Robert at ID-Tasker
Legend
November 11, 2024

@SimonLeong

 

Does it have to be a new document? How about moving each object to a new page and resizing it to fit the object?

 

Known Participant
November 11, 2024

oh wow didn't even think of this option but that's a very helpful alternative as well. clever idea.

m1b
Community Expert
Community Expert
November 10, 2024

Hi @SimonLeong, I've written a script to do part of what you want. Maybe it will be a partial help.

- Mark

 

/**
 * Make Documents For Selected Items.js
 *
 * @author m1b
 * @version 2024-11-11
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-copy-selected-object-frame-s-and-create-new-file-s-at-object-frame-size-in-indesign/m-p/14964815
 */
function main() {

    var doc = app.activeDocument,
        items = doc.selection,
        newDocs = [];

    for (var i = 0, item, dup, newDoc; i < items.length; i++) {

        item = items[i];
        newDoc = makeNewDocForItem(item);

        if (!newDoc)
            continue;

        newDocs.push(newDoc);
        dup = item.duplicate(newDoc.pages[0]);
        dup.move([0, 0]);

    }

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Make Documents For Items');

/**
 * Returns a document sized to match `item`.
 * @author m1b
 * @date 2024-11-11
 * @param {PageItem} item - an Indesign page item.
 * @returns {Document?}
 */
function makeNewDocForItem(item) {

    if (
        undefined == item
        || !item.hasOwnProperty('geometricBounds')
    )
        return;

    return newDocument(item.geometricBounds);

};

/**
 * Returns a document sized to match `bounds`
 * with specific properties.
 * @author m1b
 * @date 2024-11-11
 * @param {Array<Number>} bounds - a bounds array [T, L, B, R].
 * @returns {Document}
 */
function newDocument(bounds) {

    var width = bounds[2] - bounds[0],
        height = bounds[3] - bounds[1],
        orientation = width < height
            ? PageOrientation.LANDSCAPE
            : PageOrientation.PORTRAIT;

    return app.documents.add(

        {
            documentPreferences:
            {
                pageWidth: width,
                pageHeight: height,
                pageOrientation: orientation,
                documentBleedBottomOffset: '3mm',
                documentBleedInsideOrLeftOffset: '3mm',
                documentBleedOutsideOrRightOffset: '3mm',
                documentBleedTopOffset: '3mm',
                documentBleedUniformSize: true,
                facingPages: false,
                createPrimaryTextFrame: false,
                pagesPerDocument: 1,
                startPageNumber: 1,
                intent: DocumentIntentOptions.PRINT_INTENT,
            },
            viewPreferences:
            {
                rulerOrigin: RulerOrigin.SPREAD_ORIGIN,
                showRulers: false,
                horizontalMeasurementUnits: MeasurementUnits.MILLIMETERS,
                verticalMeasurementUnits: MeasurementUnits.MILLIMETERS,
            }
        }

    );

};
Known Participant
November 11, 2024

thanks so much. will check out the script and see how it works. many thanks 🙂