Skip to main content
Known Participant
April 18, 2017
Answered

Looking for a Page Swap Script

  • April 18, 2017
  • 1 reply
  • 851 views

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!

This topic has been closed for replies.
Correct answer rohit_ID

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

1 reply

rohit_ID
Adobe Employee
rohit_IDCorrect answer
Adobe Employee
April 18, 2017

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

Known Participant
April 18, 2017

Thank you so much, that worked!

Colin Flashman
Braniac
April 23, 2017

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!

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!