Skip to main content
Known Participant
May 28, 2023
Answered

Script to rotate image inside frame Data merge

  • May 28, 2023
  • 6 replies
  • 1069 views

Hi

I made an indesign file containes 1000 pages produced by data merge , each page contain one image

I want to  use a script to rotate Images Only with certain angle ( 45 , 90 ..... etc ) Not  rotating its graphic frame

Thanks

 

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer m1b

This script should do it.

function main() {

    // settings:
    var myAngle = prompt('Rotate all graphics by amount:', 90),
        absoluteRotation = true;

    if (myAngle == null)
        return;

    var doc = app.activeDocument,
        tm = app.transformationMatrices.add({ counterclockwiseRotationAngle: Number(myAngle) }),
        graphics = doc.allGraphics;

    for (var i = 0; i < graphics.length; i++)
        graphics[i].transform(CoordinateSpaces.PARENT_COORDINATES, AnchorPoint.CENTER_ANCHOR, tm, absoluteRotation ? MatrixContent.ROTATION_VALUE : undefined);

}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Rotate all graphics');

Note: this will set the rotate of every graphic *to* a particular angle, and running the script twice won't do anything. But if you change absolute rotation to false

absoluteRotation = false;

 then it will rotate *by* the amount each time you run the script.

- Mark

6 replies

m1b
Community Expert
Community Expert
May 28, 2023

So, you want help to write the script? A script which rotates every placed graphic in the document by the same amount? Or does it need to target particular graphics? I suggest you post a sample .indd document (just a few pages) with a screen shot of the final result you want. - Mark

Known Participant
May 28, 2023

Thanks For your Reply

I want script that rotates every placed graphic in the document by the same amount ( Not the graphic frame ) Except graphics in locked layers

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
May 28, 2023

This script should do it.

function main() {

    // settings:
    var myAngle = prompt('Rotate all graphics by amount:', 90),
        absoluteRotation = true;

    if (myAngle == null)
        return;

    var doc = app.activeDocument,
        tm = app.transformationMatrices.add({ counterclockwiseRotationAngle: Number(myAngle) }),
        graphics = doc.allGraphics;

    for (var i = 0; i < graphics.length; i++)
        graphics[i].transform(CoordinateSpaces.PARENT_COORDINATES, AnchorPoint.CENTER_ANCHOR, tm, absoluteRotation ? MatrixContent.ROTATION_VALUE : undefined);

}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Rotate all graphics');

Note: this will set the rotate of every graphic *to* a particular angle, and running the script twice won't do anything. But if you change absolute rotation to false

absoluteRotation = false;

 then it will rotate *by* the amount each time you run the script.

- Mark

Known Participant
May 28, 2023

Any help Here