Skip to main content
Known Participant
July 22, 2023
Answered

Script to rotate selected image inside frame Data merge

  • July 22, 2023
  • 4 replies
  • 2167 views

Hi

I am preparing a date merge process , I want to rotate each image of 5 images by a certain angle different from other images

I found that no object style can i apply to do that

Is there are a script to do that Automatically

This topic has been closed for replies.
Correct answer m1b

Hi @r28071715i111, my idea was that you set up the script labels before datamerge and then run script after datamerge. 

4 replies

Community Expert
July 23, 2023

My point is if there is no logic that comes in from the merged data and we have to go to every frame one by one anyhow even  in the case of using @m1b's script then why don't we do it manually. Script could help only if we can narrow down the use case of going to each frame. Something like all graphics on page 1 rotates by 15 degrees, etc.

-Manan

-Manan
Known Participant
July 23, 2023

We can't do it manually because it takes a lot of time

suppose that we have 500 pages and each page contain 5 graphic frames each of them rotate by certain angle that mean 2500 images , it will spend too much hours .

Thanks for your reply

Robert at ID-Tasker
Legend
July 23, 2023

If you know upfront which image should be rotated and by how much - and it looks like you know, as you can set labels to the frames - then you can rotate them in Photoshop BEFORE importing... 

 

m1b
Community Expert
Community Expert
July 23, 2023

Hi @r28071715i111, here's an idea (and a working script). First you select each graphic (can be the graphic or it's frame) and set its Script Label (see the Script Label panel under Windows > Utilities menu) to "rotate: 15" where the 15 means 15 degrees counterclockwise. Will that work in your case? Script is below, and I've attached a demo .indd also so you can test script with that first.

- Mark

 

/**
 * Apply rotation to graphics with a "rotate" script label.
 * eg. if label is "rotate: 15", then the graphic will be
 * rotated by 15° counter-clockwise.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
 */
function main() {

    var doc = app.activeDocument,
        tm = app.transformationMatrices.add({ counterclockwiseRotationAngle: 0 }),
        images = doc.allGraphics,
        matcher = /^rotate:(-?\d+\.?\d*)/i,
        label,
        value;

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

        label = images[i].label || images[i].parent.label;

        if (!label)
            continue;

        value = label.match(matcher);

        if (!value
            || value.length < 2
            || isNaN(value = Number(value[1]))
        )
            continue;

        images[i].transform(
            CoordinateSpaces.pasteboardCoordinates,
            AnchorPoint.centerAnchor,
            tm.rotateMatrix(-images[i].absoluteRotationAngle + value),
        );

    }

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Rotate Graphics');
Known Participant
July 23, 2023

Thanks For your Reply mark

But I have a question : Is that script work after making data merge or before ?

Ex : I want all images across pages in graphic frame 1 rotate by 10 degress 

                  all images across pages in graphic frame 2 rotate by 23 degress 

And so on

I will try your script and tell you result

Thanks for your effort in advance

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
July 23, 2023

Hi @r28071715i111, my idea was that you set up the script labels before datamerge and then run script after datamerge. 

Community Expert
July 23, 2023

Is the rotation angle variable? If so then how is it determined? If not then can't you rotate the image frame beforehand and then do the merge?

-Manan

-Manan
Known Participant
July 23, 2023

Thanks For your Replay Manan

rotation angle is variable depends on its graphic frame )

( If the image is in graphic frame 1 , rotate it by 30 degrees )

( If the image is in graphic frame 2 , rotate it by 20 degrees )

and so on

I want to select image angle degrees of all its graphic frames before i make data merge

Or

Its is possibe after making data merge but it is necessary to add in script ( From page number (  ) to page number ( )

or apply in all pages of the document

Known Participant
July 22, 2023
Any Help here !!!!!