Copy link to clipboard
Copied
Hi,
the code below should
1) open a INDD file
2) traverse all pages
3) grab all the rectangles from that page
4) and delete them.
things that work:
the script traverses trough all the pages (4 pages)
he finds all the rectangles on that page
but then:
when there are for example 5 items on that page, he shows me in that there are 5 items on that page, but when he goes in the second while loop, he only does it 3 times, when he actually should loop 5 times... that's so strange.
Result: a indd file with only a few rectangles removed, and some remain...
So, if someone could help me/show me, that would be awesome!
Thanks !
Tha code!
destination = app.open(File("/Users/anders/Desktop/46a93e71-b6bc-477f-abfd-3221f527dc44/VerticalDMA5.indd"));
destination.documentPreferences.facingPages = false;
var pages = destination.pages;
var page;
var pageItems;
var v = 0;
var z = 0;
$.writeln ("pages = " + pages.length)
while(z < pages.length) {
page = pages
pageItems = page.rectangles;
$.writeln ("number of items on page = " + pageItems.count())
while(v < pageItems.length) {
pageItem = pageItems
$.writeln("PageItem: "+pageItem+" ID: "+pageItem.id);
pageItem.remove();
v = v + 1;
}
v = 0;
z = z + 1;
}
Copy link to clipboard
Copied
Hi,
I'm a C++ programmer not a scripter, but the bug is obvious:
Jou have a list/arry of page items and remove from first to last index incrementing with each iteration.
This will delete item[0] and increment to list/array index 1, holding the third page item, as you just deleted the first.
So do a while ( list.length ) delete item[0] or alike.
Best,
Peter Schülke
Copy link to clipboard
Copied
Ohh! off course! That's so obvious!
thanks a lot, that did the trick!
Copy link to clipboard
Copied
You may also want to simplify your code:
#target "InDesign"
app.activeDocument.rectangles.everyItem().remove();
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more