Skip to main content
Known Participant
September 8, 2010
Answered

Flipping a page item

  • September 8, 2010
  • 1 reply
  • 989 views

How can I flip a page item horizontally, so that it appears on the other side of the page. I.e.: An icon in the top right corner should then be in the top left corner of the page.

This topic has been closed for replies.
Correct answer Muppet_Mark-QAl63s

Only a slightly different way… You could get the pageItem's vertical center then flip it over the page join maybe? using flip content horizontally… I only tried this left page to right but it did what I expected…

#target indesign var docRef = app.activeDocument; with(docRef){      if (spreads[0].pages.length == 2) {           var a = pages[0].pageItems[0].duplicate([0,0]);           var fph = spreads[0].pages[0].bounds[3];           var fpv = a.geometricBounds[0]+a.geometricBounds[2]/2;           a.flipItem(FlipItemOptions.horizontal, [fph,fpv], true);      } }

I see you are much quicker…

1 reply

Jongware
Community Expert
Community Expert
September 8, 2010

Horizontal flipping of the object only needs one FlipItem call, but getting it into the right position needs some calculations. Initially, I tried using a transformation matrix -- but after a couple of minutes frantically throwing in different numbers and still not getting what I wanted I resorted to my tried-and-tested "do it yourself" method

If someone can do it with a single call to transform, I'd like to see that!

if (app.selection[0].parent instanceof Page)
{
pg = app.selection[0].parent;
item_size = app.selection[0].geometricBounds;
item_width = item_size[3] - item_size[1];
pg_size = pg.bounds;
pg_width = pg_size[3] - pg_size[1];
item_pos = item_size[1] - pg_size[1];

app.selection[0].geometricBounds = [ item_size[0], pg_size[1]+pg_width-item_width-item_pos, item_size[2], pg_size[1]+pg_width-item_pos ];
app.selection[0].flipItem (Flip.HORIZONTAL, AnchorPoint.CENTER_ANCHOR);
}

BarqxAuthor
Known Participant
September 8, 2010

How about this?

app.selection[0].flipItem(Flip.HORIZONTAL, [app.activeDocument.documentPreferences.pageWidth/2,app.activeDocument.documentPreferences.pageWidth/2]);

Jongware
Community Expert
Community Expert
September 8, 2010

Uh. Yeah.

The second half of your 'flip around point" was a bit unclear, because theoretically it should be the height of the page, not the width. Then I realised it really doesn't matter, for a horizontal flip ... you could also use

app.selection[0].flipItem(Flip.HORIZONTAL, [app.activeDocument.documentPreferences.pageWidth/2, Math.PI]);

but for clarity I think I'd prefer

app.selection[0].flipItem(Flip.HORIZONTAL, [app.activeDocument.documentPreferences.pageWidth/2, 0]);

This doesn't always work, though. It needs to have the ruler origin set to the top left of your current page. Additionally, for Spreads it needs to have the Ruler per Page (I think). The flip-around-point anchor point is an absolute position (relative to the active zero point).

I guess it depends on how your document is set up (spreads or single pages) and if you have a habit of dragging the zero point around. If both are answered with "never", your method is fine. Otherwise it needs some additional checking and set-up.