13 Replies Latest reply on Oct 18, 2008 2:27 AM by (Simon_Paterson)

    JS CS3 Page Item Dimensions

      Hi there

      I'd like to change the width & height of a rectangle by certain increment. This can be easily done by manipulating geometricBounds.

      However when the rotationAngle is other than zero everything goes off the rails.

      I tried experimenting with horizontal & verticalScale but these are only relative changes. They might be useful if I knew how to get the original H&W of the rotated object. Unfortunately none of the rectangle's properties seems to be of any use.

      My other attempt was through the angle, bounding box and trigonometric hell. I was successful with flat lines. 2D rectangles proved to be too much of a challenge for me. And I still don't think this is the right approach anyway.

      So the question is: Is there any way to get or change the values in H & W fields in InD's control panel via JavaScript?

      Thanks for help
      weller
        • 1. Re: JS CS3 Page Item Dimensions
          Peter Kahrel Adobe Community Professional & MVP
          Maybe this: store the pageitem's rotation angle, set it to 0, resize the item, then restore its angle.

          Peter
          • 2. Re: JS CS3 Page Item Dimensions
            Peter Kahrel Adobe Community Professional & MVP
            Mm. The trouble, I realise a bit late, is that you don't know the anchor point around which the item was rotated.
            • 3. Re: JS CS3 Page Item Dimensions
              Level 1
              Thanks Peter

              Maybe the transform() method of Rectangle might do the job. One of it's arguments is Anchor point. Unfortunately I cannot get my head around it. Bit of rocket science to me.
              I've found a guide in the forum archive by OLE. It's for VB and therefore lost on me :( Have you got any experience with it? Do you think it might help in my case?
              weller

              Oh by the way. Thanks for your excellent o'Reilly's short cut. It set me on the right track. All my previous attempt didn't go far
              • 4. Re: JS CS3 Page Item Dimensions
                Level 1
                @#$! I've just discovered the same example for JS. I'll try to understand it and apply it to my problem. If I'm at dead end I'll surely come back with more questions.
                weller
                • 5. Re: JS CS3 Page Item Dimensions
                  Peter Kahrel Adobe Community Professional & MVP
                  Come to think of it, if you unrotate and rerotate, so to speak, the item around its centre, then it doesn't matter around which anchor it was rotated originally. Probably. Try this:

                  // set the reference point in the transform panel to center
                  app.layoutWindows[0].transformReferencePoint =
                  AnchorPoint.centerAnchor;
                  // store the item's angle
                  myAngle = myItem.rotationAngle;
                  // set angle to 0, i.e. unrotate
                  myItem.rotationAngle = 0;
                  // do your resizing
                  // rotate the item
                  myItem.rotationAngle = myAngle;

                  Peter

                  PS: Glad you liked the shortcut
                  • 6. Re: JS CS3 Page Item Dimensions
                    Level 1
                    Thanks Peter
                    It works for me. I just so cannot believe there's no direct way of getting or changing the properties that are in the control panel in InD's UI. Maybe CS4

                    weller
                    • 7. Re: JS CS3 Page Item Dimensions
                      Level 1
                      Hi weller,

                      There is, actually. It's in the transform stuff--and the cool thing is that it works with rotated objects. I'll put an example together as soon as I have time.

                      Thanks,

                      Ole
                      • 8. Re: JS CS3 Page Item Dimensions
                        sstanleyau Level 4
                        On 14/6/08 11:51 PM, "Peter Kahrel" <member@adobeforums.com> wrote:<br /><br />> Come to think of it, if you unrotate and rerotate, so to speak, the item<br />> around its centre, then it doesn't matter around which anchor it was rotated<br />> originally.<br /><br />You can also rotate, get the bounds, and then undo.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
                        • 9. Re: JS CS3 Page Item Dimensions
                          Peter Kahrel Adobe Community Professional & MVP
                          >You can also rotate, get the bounds, and then undo.

                          But you need to resize before you undo, so you'd undo the resizing, not the rotation.

                          Peter
                          • 10. Re: JS CS3 Page Item Dimensions
                            sstanleyau Level 4
                            On 15/6/08 9:43 PM, "Peter Kahrel" <member@adobeforums.com> wrote:<br /><br />> But you need to resize before you undo, so you'd undo the resizing, not the<br />> rotation. <br /><br />Oops -- of course! <br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
                            • 11. Re: JS CS3 Page Item Dimensions
                              (Simon_Paterson) Level 1
                              Ole, did you ever write up the method for doing this with the transform stuff?
                              • 12. Re: JS CS3 Page Item Dimensions
                                (Simon_Paterson) Level 1
                                Following is my attempt at writing a function for width and height. It appears to work on rotated and sheared objects. Can anyone tell me if I'm on the right track?

                                >function WidthAndHeight(myRectangle) // Returns an array [width,height]

                                ]{

                                ]] var myRectangleTopLeft = myRectangle.resolve(AnchorPoint.topLeftAnchor, CoordinateSpaces.pasteboardCoordinates, true);

                                var myRectangleTopRight = myRectangle.resolve(AnchorPoint.topRightAnchor, CoordinateSpaces.pasteboardCoordinates, true);

                                var myRectangleBottomLeft = myRectangle.resolve(AnchorPoint.bottomLeftAnchor, CoordinateSpaces.pasteboardCoordinates, true);


                                var d1x = (myRectangleTopRight[0][0] - myRectangleTopLeft[0][0]);

                                var d1y = (myRectangleTopRight[0][1] - myRectangleTopLeft[0][1]);

                                var myWidth = hypotenuse(d1x,d1y);

                                var d2x = (myRectangleTopLeft[0][0] - myRectangleBottomLeft[0][0]);

                                var d2y = (myRectangleTopLeft[0][1] - myRectangleBottomLeft[0][1]);

                                var myHeight = hypotenuse(d2x,d2y);


                                return [myWidth,myHeight];


                                function hypotenuse(d1,d2)

                                ]]]{
                                ]]]] d1 = Math.abs(d1);

                                d2 = Math.abs(d2);

                                return Math.sqrt ( Math.pow(d1,2) + Math.pow(d2,2) );

                                ]]]}


                                ]}
                                • 13. Re: JS CS3 Page Item Dimensions
                                  (Simon_Paterson) Level 1
                                  Realised that of course we don't need the absolute value of d1 and d2. Sorry.