6 Replies Latest reply on Mar 8, 2013 12:26 AM by Harbs.

    Trying to use reframe again

    Dave Saunders Level 4

      While I could have written this script three times over using geometricBounds, every now and then I recall the heated discussions with the Adobe engineer who called us all idiots for not using reframe, so I give it another go and remember why I was so heated all that time ago.

       

      frame = app.selection[0];
      page = app.documents[0].pages[0];
      pBounds = page.bounds;
      $.writeln("pBounds: " + pBounds); // => pBounds: 0,0,792,612
      frame.reframe(CoordinateSpaces.spreadCoordinates, [[pBounds[1], pBounds[0]],[pBounds[3],pBounds[2]]]);
      $.writeln("frameBounds: " + frame.geometricBounds); // => frameBounds: 396,0,1188,612
      
      

       

      I created a new document and set the rulers to points. Drew a text frame and ran the above script. Instead of moving the frame to the top-left corner of the page and resizing to match the size of the page, it did what's indicated in the comments above. The frame is the right size, it's just halfway down the page instead of at top-left.

       

      I tried this variation (newly available in CS6):

       

       

      frame = app.selection[0];
      page = app.documents[0].pages[0];
      pBounds = page.bounds;
      $.writeln("pBounds: " + pBounds); // => pBounds: 0,0,792,612
      frame.reframe(CoordinateSpaces.pageCoordinates, [[pBounds[1], pBounds[0]],[pBounds[3],pBounds[2]]]);
      $.writeln("frameBounds: " + frame.geometricBounds); // => frameBounds: 302.625,253.875,1094.625,865.875
      
      

       

      And this produces gobbledegook, although again, the frame is the right size. Just in the wrong place, off by some random amount.

       

      I think I'll go back to using geometricBounds. But can anyone explain this?

       

      Dave

        • 1. Re: Trying to use reframe again
          Dirk Becker Level 4

          page.bounds uses a different coordinate space.

           

          I just adopted Shawn's AppleScript example from that discussion, before I saw he had provided the same code later on ;-).

           

          var frame = app.selection[0];

          var page = app.documents[0].pages[0];

          var pBounds = page.bounds;

          $.writeln("pBounds: " + pBounds); // => pBounds: 0,0,792,612

          var topLeft = page.resolve(AnchorPoint.TOP_LEFT_ANCHOR,CoordinateSpaces.SPREAD_COORDINATES)[0];

          var bottomRight = page.resolve(AnchorPoint.BOTTOM_RIGHT_ANCHOR,CoordinateSpaces.SPREAD_COORDINATES)[0];

          $.writeln("topLeft: " + topLeft+" bottomRight: "+bottomRight);

          var corners = [topLeft,bottomRight];

          frame.reframe(CoordinateSpaces.SPREAD_COORDINATES, corners);

           

          Note that resolve() wraps up the provided corner coordinates in doubly nested arrays, thus the [0] dereference.

           

          For those that missed the discussion, below I've quoted the fascinating example that also considers margin preferences.

          Don't ask me to explain that one, though.

           

          Dirk

           

           

          var myPage = app.documents[0].pages[0];

           

          var pageBounds = myPage.bounds;

          var pageWidth = pageBounds[3] - pageBounds[1];

          var pageHeight = pageBounds[2] - pageBounds[0];

           

          var mTop = myPage.marginPreferences.top / pageHeight;

          var mBottom =1 - myPage.marginPreferences.bottom / pageHeight;

          var mLeft = myPage.marginPreferences.left / pageWidth;

          var mRight = 1 - myPage.marginPreferences.right / pageWidth;

           

          var mySpread = myPage.parent;

          var myFrame = mySpread.textFrames.add();

          var topLeft = myPage.resolve(

            [[mLeft, mTop], BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS],

            CoordinateSpaces.SPREAD_COORDINATES)[0];

          var bottomRight = myPage.resolve(

            [[mRight, mBottom], BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS],

            CoordinateSpaces.SPREAD_COORDINATES)[0];

          myFrame.reframe( CoordinateSpaces.SPREAD_COORDINATES, [topLeft, bottomRight]);

          • 2. Re: Trying to use reframe again
            Dave Saunders Level 4

            Thanks Dirk,

             

            It happens that I was using the page bounds only as a convenient way of getting some known cooridinates. I actually want to draw a frame on the pasteboard. But I guess that using the anchor points of the page to get some numbers is all that's needed to get started.

             

            I trust things have been well with you. I'm still working for Typefi; amaziing to think it's been almost seven years!

             

            Dave

            • 3. Re: Trying to use reframe again
              Dirk Becker Level 4

              Dave,

               

              thanks, I was also glad to see you around here - it's been a while. The years fly if you are deeply immersed in a large scale project! I've also spent the major part of the past three years with an enterprise project scripting InDesign Server and am now looking forward to more plugin work in the near future. At a certain volume javascript code just makes you envy the safeguards and tools of other languages. If I had to start another similar InDesign scripting project today I'd probably do it in Java.

               

              Dirk

              • 4. Re: Trying to use reframe again
                Harbs. Level 6

                Dirk Becker wrote:

                If I had to start another similar InDesign scripting project today I'd probably do it in Java.

                 

                Java? How'd you do that?

                • 5. Re: Trying to use reframe again
                  Dirk Becker Level 4

                  Harbs wrote:

                  Java? How'd you do that?

                   

                  Currently with technology that resembles PatchPanel. Parse the OM, add some more info to differentiate between int and float, and generate roughly 1000 classes. Works neat even though a bit slow, the generator is JavaScript right now. When execution speed starts to matter: well, I also wrote I'm looking forward to [have more time for] plugin work.

                  • 6. Re: Trying to use reframe again
                    Harbs. Level 6

                    Hmm... Sounds very interesting. Keep me posted!