Skip navigation
Currently Being Moderated

placeIntoFrame() going to wrong page

May 22, 2012 7:35 AM

Tags: #script #javascript #indesign_cs5.5 #scripting

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.

  • Currently Being Moderated
    May 22, 2012 8:19 AM   in reply to islander1970

    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?



    Mark as:
  • Currently Being Moderated
    May 22, 2012 9:16 AM   in reply to islander1970

    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.)

    Mark as:
  • Currently Being Moderated
    May 22, 2012 10:32 AM   in reply to islander1970

    ...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.

    Mark as:
  • Currently Being Moderated
    May 29, 2012 10:07 AM   in reply to islander1970

    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 and then pages.itemByID() throughout, and forget about index, if you're going to stick with the page as your target for placeIntoFrame().

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points