Hi Mark,
method move() and also method duplicate() have two arguments.
The to and the by argument. If you do only one argument the to argument is used.
What are the capabilities of the to argument?
This depends on the object you want to move. Is it text, is it a page, is it a graphic frame or text frame?
Your sample is assuming that you selected a rectangle graphic frame. So look up method move() with object rectangle in DOM documentation: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Rectangle.html#d1e217191__d1e220631
And there you have them, several targets where you can move your rectangle to:
[ x , y ] Coordinates x and y given as array
Page
Spread
Layer
So define your target. If it is a page, let's say page 3 of your document, do it like that:
var targetPage = app.documents[0].pages[2];
var myRectangle = app.selection[0];
myRectangle.move( targetPage );
What can go wrong with that?
Hm. If the selected rectangle is nested. Means is part of a group, is pasted inside another graphic frame, is anchored to text, is part of a graphic cell. Come back if you have more issues with special cases like that…
Regards,
Uwe Laubender
( ACP )