5 Replies Latest reply on Dec 29, 2011 5:14 AM by gunder2011

    How to check if a page item is outside a page

    gunder2011

      Hi all

       

      I'm a developer tasked with doing some automation in InDesign, using scripting via .NET. As I'm a developer, I'm not really fluent in the language of layout, so please bear with me.

       

      My script creates a variable amount of TextFrame's on a page and moves them, and then rotates them. Some of them might exit the page on the right side. If only one of the text frame's bottom-right anchor point happens to be outside of the page to the right, I need to detect it. It's no problem iterating over the text frames, but the challenge is how I determine if a text frame's bottom-right anchor point is positioned outside of the page.

       

      I've looked at GeometricBounds, but as soon as the position is to the right of the page, the coordinates start from 0 again. So I can't do it like GeometricBounds.X > Page.Width, because GeometricBounds.X will less than Page.Width when it's to the right of the page.

       

      I've also looked at PageItem.Resolve, but that function really confuses me. I tried resolving the anchor point to pasteboard coordinates, and that seems to work okay. But then I have to get the page's right edge in pasteboard coordinates, and it doesn't seem I can use PageItem.Resolve to get that.

       

      I've looked at the programming guide to figure out how the different coordinate systems work together, but when I use PageItem.Resolve, I get results that doesn't seem to be correct according to where the coordinate systems should be.

       

      I'm sure it's easy to detect if a text frame is outside a page, but I just need a pointer in the right direction. Can anyone help me with that? :-)

       

      Thanks in advance.

       

      PS: I'm scripting for InDesign CS3.

        • 1. Re: How to check if a page item is outside a page
          Harbs. Level 6

          1) Use visibleBounds instead of geometricBounds (for transformed objects).

          2) set the rulerOrigin to spread.

          3) Don't use .NET unless you enjoy a painful experience.

           

          Good luck,

          Harbs

          • 2. Re: How to check if a page item is outside a page
            gunder2011 Level 1

            Thank you so much Harbs! - You helped me solve the problem!

             

            I tried setting the ruler origin to spread, and that made it possible for me to compare the coordinates returned from VisibleBounds directly. (And thanks for the tip about VisibleBounds instead of GeometricBounds)

             

            Again, thanks alot, really. I've spent some time now trying to figure this one out, so it's really a relief to get this one resolved.

             

            Oh, and even though it's not really related to my question or the solution, I can't help but comment on your 3rd point. I've certainly had my share of challenges using InDesign scripting from .NET, but once you know the quirks, it works pretty well and I certainly don't consider it a painful experience. As I said there's some issues to be aware of, but not something that stops me in my day-to-day work or slows me down. I've only worked with scripting InDesign via .NET for the last 2½ months, but at this point, I would definitely choose .NET scripting over Javascript even despite the quirks. But that's just my oppinion. :-)

             

            Thanks for your help Harbs!

            • 3. Re: How to check if a page item is outside a page
              Harbs. Level 6

              gunder2011 wrote:

              ...I've certainly had my share of challenges using InDesign scripting from .NET, but once you know the quirks, it works pretty well and I certainly don't consider it a painful experience...

              I'm glad to hear it! I have never attempted to use .NET myself, but from others I've gathered that it can be quite painful.

               

              If it works for you, far be it from me to differ!

               

              Harbs

              • 4. Re: How to check if a page item is outside a page
                bduffy323 Level 1

                I know this question has already been answerd, and I think I posted a similiar question under "accessing page items in the document but outside the page bounds" found here -> http://forums.adobe.com/message/4105283#4105283

                But I would like to know how you maintained access to these textframes that are off the edge of your page? The only way I can get to them is if they are atleast touching the page bounds and I can use myPage.pageItems.

                • 5. Re: How to check if a page item is outside a page
                  gunder2011 Level 1

                  I maintain access to the textframes by having a variable point to them. I get this variable when I create the textframe, like this:

                  var textframe = page.TextFrames.Add();

                   

                  Then I use the variable 'textFrame' to do whatever I need to do (Transform it, insert text etc.). If I wanted to do something with the textframe later on, I would just hang on to the variable, or put it into a List.

                   

                  I haven't had any need for myPage.PageItems, so I haven't used that.