Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can't remove all Rectangles

Guest
Oct 12, 2009 Oct 12, 2009

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;

}

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 12, 2009 Oct 12, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 13, 2009 Oct 13, 2009

Ohh! off course! That's so obvious!

thanks a lot, that did the trick!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 22, 2009 Oct 22, 2009
LATEST

You may also want to simplify your code:

#target "InDesign"

app.activeDocument.rectangles.everyItem().remove();

Dirk

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines