how to delete pages from indesign by using AS?

can I use AS to tell application indesign: delete/remove all odd pages?

G5

Posted on Apr 28, 2008 1:00 PM

Reply
4 replies

Apr 29, 2008 5:28 PM in response to Fist

Funny, I saw this and thought, piece of cake. Then I realized that if you delete in order of the pages, you then reorder the later pages and start deleting what should be an even page. For example, if I have pages 1, 2, 3, 4, and 5 and I get page count and start deleting the odd pages (1, 3, and 5), the first loop will delete page 1 which makes page 2 page 1, page 3 page 2, page 4 page 3, page 5 page 4. This is a problem. On the second loop, I tell InDesign to delete page 3 but I am actually deleting page 4. So 20 minutes of thought, here is a rough go at it.

The idea here is that you need to start at the end of the document so you ensure that you are not reordering. I use two lists. The first contains the number of all odd pages determined by a loop that is based on the total number of pages in the document {1,3,5,7...}. Once I have this list, I reverse it to I have {...7,5,3,1}. With the list reversed, it is a simple repeat loop to delete each odd page from the end of the document forward.

Hope this helps. Nice challenge.


--Define some lists
property oddPageList : {}
property oddPageListReverse : {}

tell application "Adobe InDesign CS3"

tell document 1
--defines some basic variables
set pageCount to count of pages
set i to 0

repeat until i = pageCount
set i to i + 1
--figure out which pages are odd numbers and append to first list
if i mod 2 > 0 then
set the end of oddPageList to i
end if
end repeat
--revers the order of the list so you delete from the end of the document forward
set oddPageListReverse to (reverse of oddPageList)


repeat with i in oddPageListReverse
--delete the pages in reverse order
delete page i

end repeat

end tell

end tell

Apr 30, 2008 8:07 AM in response to Strontium90

This is an approche I didn't thought of! It works, but all my even pages are gone.
Is this something in the deviding even an dodd pages in the list?
So I thought it would be an idea to ask which pages must be deleted.
But then both (start from top if even, start from the end if odd) loops must be setup

This is how far I am so far.
--select any indesignfile
set vselectdoc to choose file with prompt "choose an indesignfile"
--select even/odd pages to delete
set vpagelist to choose from list {"even pages", "odd pages"} with prompt "Which page must be deleted?" default items {1} OK button name "OK" cancel button name "Default" without multiple selections allowed and empty selection allowed
property oddPageList : {}
property oddPageListReverse : {}
property evenPageList : {}

tell application "Adobe InDesign CS3"
--all windows will be ignored so you have to be sure that the indd is ok
set the user interaction level of script preferences to never interact
open vselectdoc
tell document 1
--defines some basic variables
set pageCount to count of pages
set i to 0

repeat until i = pageCount
set i to i + 1
--figure out which pages are odd numbers and append to first list
--if not add to evenlist
if i mod 2 > 0 then
set the end of oddPageList to i
end if
end repeat
--revers the order of the list so you delete from the end of the document forward
set oddPageListReverse to (reverse of oddPageList)


repeat with i in oddPageListReverse
--delete the pages in reverse order
delete page i

end repeat

end tell

end tell

Apr 30, 2008 11:42 AM in response to Fist

Hello

I guess you lost even pages because physical pagination (page number on each page) and logical page number are different in your document.

Anyway, you may try the following script, which will let you choose whether even or odd (logical) pages to be deleted.

Good luck,
H

--SCRIPT (NOT TESTED)
set mss1 to "Which pages to delete?"
set pp to {"even pages", "odd pages"}
tell (choose from list pp with prompt mss1 default items {pp's item 1})
if it is false then error number -128 -- user cancel
set _even to its item 1 = pp's item 1
end tell

tell application "Adobe InDesign CS3"
tell document 1
set n to count pages
if _even then
set m to n - n mod 2 -- max even number <= n
else
set m to n - 1 + n mod 2 -- max odd number <= n
end if
repeat with i from m to 1 by -2
delete page i
end repeat
end tell
end tell
--END OF SCRIPT

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how to delete pages from indesign by using AS?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.