Copy link to clipboard
Copied
I have a script that does some useful operation for my document. But it always need have selected part of document, like
if( app.selection.length > 0 ) ...
Could you ask me how can I select all pages from indesign document. I can have a lot of pages. And I have a lot of .indd files
I tried use app.activeDocument.pages.item(0).allPageItems; but it isn't effect even for page =(
Maybe I can use 'for' loop but maybe there is some function for selecting all document, not only one page
Thanks
Of course:
myPages = app.activeDocument.pages.everyItem().getElements(); // array of references to pages of document
for (var k = myPages.length - 1; k >= 0; k--) {
myItems = myPages
for (var j = myItems.length - 1; j >= 0; j--) {
processItem(myItems
}
}
This processes everything from back to front which is usually the safe approach and is potentially a little bit quicker than going the other way.
You still need to write the processItem function.
Dave
Copy link to clipboard
Copied
A script does not have to make a selection to operate on objects, and indeed, you can't select beyond either the current spread or current text range. Selecting is what you have to do to use the user interface but a script can operate on any objects you can address ... as you seem to understand from the snippet of code you provided.
app.activeDocument.pages.item(0).allPageItems should have given you an array of all the page items on the first page of the active document, but because it's an array you have to loop through the items working on each one:
myItems = app.activeDocument.pages[0].allPageItems;
for (var j = myItems.length - 1; j >= 0; j--) {
processItem(myItems
}
where processItem is a function that does whatever you want to do to each item.
Dave
Copy link to clipboard
Copied
Can I use 'for' loop for iterating all pages in document? How can I get number of pages for this operation, tell me please
Copy link to clipboard
Copied
Of course:
myPages = app.activeDocument.pages.everyItem().getElements(); // array of references to pages of document
for (var k = myPages.length - 1; k >= 0; k--) {
myItems = myPages
for (var j = myItems.length - 1; j >= 0; j--) {
processItem(myItems
}
}
This processes everything from back to front which is usually the safe approach and is potentially a little bit quicker than going the other way.
You still need to write the processItem function.
Dave
Copy link to clipboard
Copied
Hi, Dave Saunders
I run this and get an error the error soruce : processItem(myItems
can someone tell me why?
Copy link to clipboard
Copied
Hi
I have a problem with this script
It does not work with element outside of the page:
ELEMENTS OUTSIDE THE PAGE:(does not get all elements..)
ELEMENTS_INDIDE_THE_PAGE(working)
Thanks
Copy link to clipboard
Copied
It is look like I found the solution:
myItems = app.activeDocument.pageItems.everyItem().getElements();
for (var k = myItems.length - 1; k >= 0; k--) {
$.write(myItems
}