7 Replies Latest reply: May 29, 2012 10:07 AM by absqua RSS

    placeIntoFrame() going to wrong page

    islander1970

      Hello all,

       

      I have a rule in a JS script that is supposed to move an XML element into it's own frame on the page it was placed on.

       

      My script correctly returns the page and its index that the XML element is on, but the placeIntoFrame() command keeps putting it on the first page (0 index).

       

      Any help would be greatly appreciated.

       

      Thank you.

       

      Here is the section of code:

       

          var myParentPageIndex = myElement.xmlContent.parentPage.index;

           // myParentPageIndex returns the correct page index number
                     
          modWidth = 3.337;
          modHeight = 3.063;
          if (modCount > 1) {
              myY1 = pageBottom-(modHeight*modCount) - (adGap * (modCount - 1));
          }
          else {
              myY1 = pageBottom-(modHeight*modCount);
          }
          myY2 = myY1 + modHeight;


          var myFrame = myElement.placeIntoFrame(myDocument.pages.item(myParentPageIndex), [myY1,pageRight-modWidth,myY2,pageRight]);

           // myFrame keeps appearing on page.item(0) despite myParentPageIndex being 0,1,2 etc.

        • 1. Re: placeIntoFrame() going to wrong page
          absqua Community Member

          The problem isn't placeIntoFrame() but how you're getting your page reference. The index of the page is its index within its parent spread, not the document. (The index of every page in a document with all single-page spreads will be 0.) So maybe get its id instead and then use pages.itemByID instead.

           

          But why not just use move() on your rectangle, if your element is already placed?

           

          Jeff

          • 2. Re: placeIntoFrame() going to wrong page
            islander1970 Community Member

            Hmm, when I put an alert after var myParentPageIndex = myElement.xmlContent.parentPage.index;

            I do get the index number I'm expecting (0,1,2). So, are you saying that using that index for myDocument.pages.item(myParentPageIndex) won't work? I guess I'm confused as to why it wouldn't if the script is retrieving the expected index. (I'm not getting all 0's in the above line)

             

            I'll look at move(). I'm new to this and learning as I go. I had placeIntoFrame because originally I had been trying to do it on the fly instead of after the content was on the page.

             

            Thanks again for your help.

            • 3. Re: placeIntoFrame() going to wrong page
              absqua Community Member

              So I'm guessing your pages 0, 1 and 2 are three pages on one spread? If so, then I suspect there's a mismatch between the coordinates you're feeding into the placeIntoFrame() and your viewPreferences.rulerOrigins—that is, one is relative to the page and the other is relative to the spread.

               

              Try setting myDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN; and see if that gives you the results you're expecting. (FWIW, though, I would probably leave the origin at the spread and figure out my offsets from there rather than from the page. It's less confusing to just always do everything from the spread. Setting that preference will quickly tell you whether that's the problem though.)

              • 4. Re: placeIntoFrame() going to wrong page
                islander1970 Community Member

                Setting that did produce the results I had been expecting. I'll try to adjust to the spread instead.

                 

                Regarding changing placeIntoFrame() to move(), it doesn't seem to be working. These are PDFs coming in as the href property of the element, and by default are placed into an inline frame. If I try to use the move method, nothing happens. Keeping the placeIntoFrame() works, though. I know it's a bit redundant. Any thoughts on why move() isn't working with these elements? I made sure to select the rectangle of each by using myElement.xmlContent.parent but they won't move. Is it because they are already anchored/inline at that point?

                • 5. Re: placeIntoFrame() going to wrong page
                  absqua Community Member

                  ...but they won't move. Is it because they are already anchored/inline at that point?

                   

                  Yes. I didn't realize we were talking about inline items. In that case, placeIntoFrame() looks like your best bet.

                   

                  I'll try to adjust to the spread instead.

                   

                  Whatever works—but it does tend to simplify things. You'll meet less resistance from InDesign that way.

                  • 6. Re: placeIntoFrame() going to wrong page
                    islander1970 Community Member

                    Thanks once more for all your help.

                     

                    I think I have one last thing confusing me on my end.

                     

                    Say I have an element on the third page of my document (left page of second two-page spread in the document)

                     

                    alert(myElement.xmlContent.parentPage.name) returns "3" as I expected, but

                    alert(myElement.xmlContent.parentPage.index) returns "0" when I am expecting  "2" (third page)

                     

                    I'm using this index to move the element to it's own frame (unanchored), but since it isn't the page index I'm expecting, the elements are being moved to the wrong place.

                     

                    I'm sure I'm missing something here as far as spread/pages/indexes work. Any help would be greatly appreciated.

                     

                    Thank you

                    • 7. Re: placeIntoFrame() going to wrong page
                      absqua Community Member

                      It sounds like the same issue I explained upthread. The index of the page is its index within its parent spread, not within the document. So the index of the first page in any spread—which your page "3" is—will be 0. Probably better to use page.id and then pages.itemByID() throughout, and forget about index, if you're going to stick with the page as your target for placeIntoFrame().