Copy link to clipboard
Copied
There is a MyPage.Add()... There is no MyPage.remove()?
Can I remove a given page number with a script?
The problem:
I have a facing pages problem. I essentially need to delete two pages, leave two pages, delete two and so on for about 2000 pages. Sure I could click and delete, but what would be the fun in that?
The pages are created from a facing-pages datamerge. Why CS4 can't handle facing pages datamerge is beyond me... Either way, I need a work around.
Visually in the PAGES tab, what I have is this
Data Merge Entry Data Merge Entry
Facing Page A | Facing Page B |
---|---|
Data Merge Entry A | Data Merge Entry A |
Data Merge Entry B | Data Merge Entry B |
Data Merge Entry C | Data Merge Entry C |
Data Merge Entry D | Data Merge Entry D |
Resulting in A,A,B,B,C,C,D,D, etc.
What I need to end with is
A | B |
---|---|
A | |
B | |
C | |
D |
Resulting in A,B,C,D, etc.
The rules: The database is untouchable. Facing Pages Side A and Side B are formated differently.
Any and all help or information leading to a working work-around willl be handsomly rewarded the moment I get my check from a rich African uncle who, I sadly found out through an email today, had recently passed away.
Many thanks!
Marc
1 Correct answer
But there is a myPage.remove()
Are there threaded text frames on the pages you want to remove? In a script, this behaves just like in the UI: threaded text is shifted to the next frame in the thread (usually, on the next page). So if that's the case, this script will work but not the way you intended it.
Anyway, you want to remove one page, then skip two pages -- remove two pages -- skip 2 -- etc., until the end of the document.
This Javascript should do it:
...var curpage = 0;
app.activeDocument.pages
Copy link to clipboard
Copied
>There is no MyPage.remove()?
There is! When you add a page, you add it to the page collection, so your starting point is the page collection:
myDoc.pages.add (...);
To delete a page, your starting point is not the page collection, but the page itself. For instance, to delete the sixth page, you would use this:
myDoc.pages[5].remove ();
(JavaScript starts counting at zero, so page 6 is the fifth page.) Note the difference between pages and page[5]: the former is the collection of pages, the latter is one page.
Peter
Copy link to clipboard
Copied
Hi Peter,
I saw your response here and was hoping you could assist me, I am trying to use your code to delete a page in my document (page 3 to be specific or javascript page 2). I have used the method you noted above ( myDoc.pages[5].remove (); ) however it does not seem to work. I have entered the javascript as a mouse down action on a radio button. I would really appreciate your assistance here?
Copy link to clipboard
Copied
But there is a myPage.remove()
Are there threaded text frames on the pages you want to remove? In a script, this behaves just like in the UI: threaded text is shifted to the next frame in the thread (usually, on the next page). So if that's the case, this script will work but not the way you intended it.
Anyway, you want to remove one page, then skip two pages -- remove two pages -- skip 2 -- etc., until the end of the document.
This Javascript should do it:
var curpage = 0;
app.activeDocument.pages[curpage].remove();
while (curpage < app.activeDocument.pages.length)
{
curpage += 2;
app.activeDocument.pages[curpage].remove();
app.activeDocument.pages[curpage].remove();
}
It boings out with an error at the end if your document contains an odd number of pages (?) because it might try to remove a page after the last one, but that's not a critical error, methinks.
I've tested it on a 30+ document, and it correctly deleted #1, then #4 and #5, then #8 and #9, etc. Still, paranoia is a healthy lifestyle (when applied to computers), so run it on a copy, will ya.
Copy link to clipboard
Copied
Thank you both very much for the help! That code worked like a charm!
-Cheers!
Marc

