5 Replies Latest reply on Sep 8, 2010 4:53 AM by Muppet Mark-QAl63s

    Flipping a page item

    Barqx Level 1

      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.

        • 1. Re: Flipping a page item
          [Jongware] Most Valuable Participant

          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);
          }
          
          1 person found this helpful
          • 2. Re: Flipping a page item
            Barqx Level 1

            How about this?

             

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

            • 3. Re: Flipping a page item
              [Jongware] Most Valuable Participant

              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.

              1 person found this helpful
              • 4. Re: Flipping a page item
                Barqx Level 1

                I don't drag around the zero. You do mention a good point there though with the two pages. If I do the flipping on the second page of a spread, things get lost.

                 

                Edit: I just tried your script. For some reason, nothing moves at all. :/

                • 5. Re: Flipping a page item
                  Muppet Mark-QAl63s Level 4

                  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…