2 Replies Latest reply on Mar 12, 2012 6:13 AM by MarkWalsh

    resize/transform pageitem - centered on page/spread

    MarkWalsh Level 4

      I've gotten just about everything done that I need to in my current project, except I am struggling with how to resize or transform a pageitem from the center of a page and/or spread (I will eventually need to do both). To complicate things, I have gotten different references from different sources for the same enumerations (i.e. CoordinateSpaces.spreadCoordinates or CoordinateSpaces.SPREAD_COORDINATES), and I have tried both but with no success on either front. Here are some of the things I have tried  (given a reference to a pageItem 'pi', a scaleMatrix 'myScaleMatrix', and the scaleFactor = the percentage I want to scale i.e 1.25):


      pi.transform(CoordinateSpaces.SPREAD_COORDINATES, AnchorPoint.centerAnchor, myScaleMatrix);


      pi.resize(CoordinateSpaces.spreadCoordinates, AnchorPoint.centerAnchor, ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY, [scaleFactor, scaleFactor], true, false);




      Can someone help by providing me the correct line of code to scale a pageItem by 'scaleFactor' from the center point of both the page and the spread, so I can get this working properly? And any direction that might help me understand the different parameters and their usage would be helpful. I've been reading through whatever I could find about transformation matrix', but I still can't wrap my head around what I'm doing wrong.

        • 1. Re: resize/transform pageitem - centered on page/spread
          Marc Autret Level 4

          Hi Mark,




          This may help you:



          So here is a possible approach if you are using ID CS5/5.5:


          // . . .
          // Assumed that a page item 'pi' is already defined
          // ...
          // Settings
          // ---
          var SCALE_FACTOR = .5,        // 50%
              PAGE_CENTER = true;    // use page relative origin?
          // Compute the transformation origin
          // (Note: parentPage was not available before CS5)
          // ---
          var ref = PAGE_CENTER ? pi.parentPage : pi.parentPage.parent,
              origin = ref.resolve(AnchorPoint.CENTER_ANCHOR, CoordinateSpaces.PASTEBOARD_COORDINATES)[0];
          // Scale
          // ---
              origin, // absolute coord. in the pasteboard space





          • 2. Re: resize/transform pageitem - centered on page/spread
            MarkWalsh Level 4

            Thanks, that did the trick. I'm currently using CS4 (although I have CS5 if it becomes necessary), so I modified the code slightly for my needs. Since I have a reference to the page already, I used that instead of using pi.parentPage - for now I can get by with using the page coordinates; when I eventually need to get the spread, I'll either run the code in CS5, or see if I can work out how to reference the spread in CS4.


            I still feel a bit at a loss when it comes to working with the different coordinates values, I'll reread your referenced post and any other info I can find and hopefully I'll get it sometime in the future.


            Thanks for the help!