Indesign - Delete Rectangle 1 on every page of document

Hello,

I have a very simple applescript somewhat created but I continually get an error when running it. I’d like to delete the one and only graphic frame on every page of an Indesign document. (500 pages)

tell application “Adobe InDesign CS5.5”
tell active document
set thebox to rectangle 1
repeat with x from 1 to count pages
set ThisPage to page x
tell ThisPage
delete the thebox
end tell
end repeat
end tell
end tell

Once it runs, it deletes the first graphic box on page one and then throws an error:

error “Adobe InDesign CS5.5 got an error: Can’t get rectangle id 58282 of spread id 58224 of document id 10.” number -1728 from rectangle id 58282 of spread id 58224 of document id 10

I run it again and it does page 2 and then another error…just like the previous.

Any help would be appreciated.

Model: Mac
Browser: Firefox 38.0
Operating System: Mac OS X (10.10)

Hi. If you inspect your code in the Event log, you can see how your reference to thebox shares the same address as an item that you just deleted. You could define thebox within the scope of the tell thispage block, or, assuming there is always a corresponding object, get all the addresses en masse, so there is no conflict.

tell application "Adobe InDesign CS3"'s document 1 to delete (pages's rectangle 1)

Marc Anthony,

You are awesome…thanks for making it so simple.

Really appreciate it.

s