Copy link to clipboard
Copied
Hi all -
I was wondering if anyone has come across a page swap script. Something simple that will popup a dialogue box and you can enter 2 pages to switch locations (without changing the location of any other pages). I don't really know much about scripting at all, so I wasn't sure if it was even possible but I did I find the below from a few years ago (from indiscripts):
function swapPages(p0, p1)
{
if (p0 == p1) return true;
var pages = app.activeDocument.pages;
var pg0 = pages.itemByName(''+p0); // force string argument
var pg1 = pages.itemByName(''+p1); // force string argument
if ( pg0.documentOffset > pg1.documentOffset ) return swapPages(p1,p0);
try {
pg1.move(LocationOptions.AFTER,pg0);
pg0.move(LocationOptions.AFTER,pages.itemByName(''+p1));
return true;
}
catch(ex) {return false;}
}
// usage:
swapPages(28,34);
This works great but the issue is it will only swap the 2 pages listed at the end (28 and 34). Was wondering how difficult would it be to adjust this to create a dialogue box when you run it, and choose the pages you want to swap.
Thanks in advance!
Hi
So you need a user input for your pages to be swapped. Please try following:
var page1 = Number(prompt ("Enter Page1", 100));
var page2 = Number(prompt ("Enter Page2", 100));
swapPages(page1,page2);
This will prompt you a dialog to enter the page numbers. Also 100 is what a default value will be shown which you can change to anything.
Hope this resolves what you are trying to do.
Thanks
Copy link to clipboard
Copied
Hi
So you need a user input for your pages to be swapped. Please try following:
var page1 = Number(prompt ("Enter Page1", 100));
var page2 = Number(prompt ("Enter Page2", 100));
swapPages(page1,page2);
This will prompt you a dialog to enter the page numbers. Also 100 is what a default value will be shown which you can change to anything.
Hope this resolves what you are trying to do.
Thanks
Copy link to clipboard
Copied
Thank you so much, that worked!
Copy link to clipboard
Copied
I'd recommend that opening poster read further into the comments on the indiscripts page that featured the script (Indiscripts :: Swapping and Reordering Pages ) as another scripter (Fabian the blind) had indeed written the script with a user interface rather than one prompt after another.
Despite that, I didn't know any of these 3 scripts existed (swap pages no UI, swap pages with UI, reorderpages) and they're all pretty cool!