@Learner – what do you mean exactly by "floats"?
And how about the "same position"?
Can you give us some screenshots to illustrate the problem?
Thanks for your reply.
What i mean the same position is, say for example a figure placed on the top of the 2nd page of the active document it needs to be moved to the top of the 3rd page.
1 person found this helpful
for (var idx = 0; idx < app.activeDocument.allPageItems.length; idx++)
var pageItem = document.allPageItems;//first object
//var pageItem = document.allPageItems[idx];//all objects
pageItem.move(app.activeDocument.pages);//this will place the first object in first page
pageItem.move([0,0]);//object position goes here
1 person found this helpful
@Learner – you can duplicate the object to the next page and remove the original.
If the original one is anchored you also have to account for its position, because duplicating an anchored object will move it.
Here an example for duplicating a selected object to the same page.
//DuplicateAnchoredObject_SELECTION_SNIPPET.jsx //Uwe Laubender /** * @@@BUILDINFO@@@ DuplicateAnchoredObject_SELECTION_SNIPPET.jsx !Version! Fri Apr 12 2013 07:53:31 GMT+0200 */ var sel = app.selection; var x = sel.geometricBounds; var y = sel.geometricBounds; //The duplicate() method without an optional argument: var dup = sel.duplicate(); //NOW: the duplicated objects is at the inner border of the page //To move it to its original position we need the following: var xd = dup.geometricBounds; var yd = dup.geometricBounds; dup.move(undefined,[x-xd,y-yd]);
That snippet can be enhanced for duplicating to a certain page, because the duplicate() methods can take arguments like "Page", "Layer", "Spread" etc. For details see the DOM documentation at:
One caution here: to make that work the way you want with facing pages, you have to take into account, that your coordinate system must be changed to "per page" by the property "RulerOrigin" of the ViewPreferences.
This said, here is a working example for duplicating a selected object to page 3 of the current document:
//DuplicateAnchoredObject_TO-DIFFERENT-PAGE_SELECTION_SNIPPET.jsx //Uwe Laubender /** * @@@BUILDINFO@@@ DuplicateAnchoredObject_TO-DIFFERENT-PAGE_SELECTION_SNIPPET.jsx !Version! Tue May 14 2013 10:11:29 GMT+0200 */ var d=app.documents; var oldRulerOrigin = d.viewPreferences.rulerOrigin; var sel = app.selection; var x = sel.geometricBounds; var y = sel.geometricBounds; //In case of facing pages we change the ruler origin: d.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN; //Duplication of selected object: var dup = sel.duplicate(d.pages); //NOW: the duplicated objects is at the inner border of the page //To move it to its original position we need the following: var xd = dup.geometricBounds; var yd = dup.geometricBounds; dup.move(undefined,[x-xd,y-yd]); //Restore the original ruler origin: d.viewPreferences.rulerOrigin = oldRulerOrigin;
Of course, thiese snippets are working also with not anchored objects…