Skip to main content
jacobs40370360
Participant
January 12, 2025
Answered

Script to flip objects on all pages

  • January 12, 2025
  • 2 replies
  • 465 views

Hi I'm looking for a script that will flip all objects on all pages of the document on the unlocked layers only. I have a script that I found here that will flip only the object selected but that is very tedious (and can also be done with the transform tool)  when I'm dealing with 250+ page documents. Thanks for any leads!

Correct answer m1b

Hi @jacobs40370360, I'm sure there are further complexities, but here is a simple approach that does what you ask. See if it helps.

- Mark

 

/**
 * Flip Items Horizontally.js
 *
 * Flips every page item horizontally, unless its layer is locked or not visible.
 *
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-flip-objects-on-all-pages/m-p/15084291
 */
function main() {

    var doc = app.activeDocument,
        items = doc.pageItems;

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

        var item = items[i];

        if (
            undefined == item
            || !item.hasOwnProperty('geometricBounds')
            || !item.itemLayer
            || item.itemLayer.locked
            || !item.itemLayer.visible
        )
            continue;

        item.transform(
            CoordinateSpaces.PARENT_COORDINATES,
            [[0, 0], BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS, CoordinateSpaces.INNER_COORDINATES],
            app.transformationMatrices.add({
                horizontalTranslation: item.geometricBounds[3] - item.geometricBounds[1],
                horizontalScaleFactor: -1,
                verticalScaleFactor: 1,
            })
        );

    }

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

 

2 replies

Robert at ID-Tasker
Legend
January 12, 2025

@jacobs40370360 

 

Do you want to "flip" or FLIP properly? 😉

 

 

And why do you want to flip your objects? And what kind of objects?

 

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
January 12, 2025

Hi @jacobs40370360, I'm sure there are further complexities, but here is a simple approach that does what you ask. See if it helps.

- Mark

 

/**
 * Flip Items Horizontally.js
 *
 * Flips every page item horizontally, unless its layer is locked or not visible.
 *
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-flip-objects-on-all-pages/m-p/15084291
 */
function main() {

    var doc = app.activeDocument,
        items = doc.pageItems;

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

        var item = items[i];

        if (
            undefined == item
            || !item.hasOwnProperty('geometricBounds')
            || !item.itemLayer
            || item.itemLayer.locked
            || !item.itemLayer.visible
        )
            continue;

        item.transform(
            CoordinateSpaces.PARENT_COORDINATES,
            [[0, 0], BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS, CoordinateSpaces.INNER_COORDINATES],
            app.transformationMatrices.add({
                horizontalTranslation: item.geometricBounds[3] - item.geometricBounds[1],
                horizontalScaleFactor: -1,
                verticalScaleFactor: 1,
            })
        );

    }

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

 

jacobs40370360
Participant
January 14, 2025

Worked like a charm, thanks so much for your help!

m1b
Community Expert
Community Expert
January 14, 2025

Good to hear!