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