Copy link to clipboard
Copied
Hi!
I have a script that loops over each page in the document and does a number of things. In some of my documents I have a few pages I want to ignore at the beginning so for those docs I want a new Pages object pointing to a limited number of pages, starting from the first page where my mainTextFrame starts and then every page until the end of the document. Pages.itemByRange() would seem ideal for this, but I'm running into problems.
var bookPages = myDoc.pages;
var newPageRange = bookPages.itemByRange(mainTextFrames[0].parentPage, bookPages[bookPages.length-1]);
I thought this would work but apparently the function returns a Page object (though the API says it returns Pages). The returned object seems to contain all information from all Pages in the range but I don't know how to extract it in a coherent way. For instance newPageRange.index returns an array of all indexes of these pages. I want to be able to loop over these pages like I can with the original myDoc.pages array.
I also tried:
newBookPages = newPageRange.properties;
But even though this gives me an array to loop over it is not an array of pages which is what I need for the script I've written.
Is it just me or is the documentation really unclear about this? Any suggestions?
Hi Simon,
resolve the returned value from itemByRange() to an array of page objects by using getElements().
Example that is working with a selected frame on a document page:
...var doc = app.documents[0];
var pages = doc.pages;
var start = app.selection[0].parentPage;
// doc.pages is a collection so we could use this to access the last one in the document:
var end = pages[-1];
// range could also be a collection:
var range = doc.pages.itemByRange( start , end );
// Resolve the collection of pages to an array
Copy link to clipboard
Copied
Hi Simon,
resolve the returned value from itemByRange() to an array of page objects by using getElements().
Example that is working with a selected frame on a document page:
var doc = app.documents[0];
var pages = doc.pages;
var start = app.selection[0].parentPage;
// doc.pages is a collection so we could use this to access the last one in the document:
var end = pages[-1];
// range could also be a collection:
var range = doc.pages.itemByRange( start , end );
// Resolve the collection of pages to an array of pages:
var arrayOfRange = range.getElements();
// Then loop the array…
Regards,
Uwe
Copy link to clipboard
Copied
Also see perhaps into some threads here in the forum where getElements() is discussed.
And read into this by Marc Autret: Indiscripts :: On ‘everyItem()’ – Part 2
Regards,
Uwe
Copy link to clipboard
Copied
Thanks. I will read in on getElements() and the link you sent. I only searched for the itemByRange() and couldn't really find anything that helped me there. But your solution works perfectly.