Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
doc = app.activeDocument;
for (i = 0; i < doc.pages.length; i++)
{
p_items = doc.pages.allPageItems;
for (j = 0; j < p_items.length; j++)
{
dupl = p_items.duplicate();
dupl.label = 'duplicate';
doc.pages.groups.add ([dupl, p_items]);
}
}
doc.groups.everyItem().ungroup();
doc.pageItems.item ('duplicate').remove()
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
var items = page.pageItems.everyItem().getElements().slice(0)(to get an array of all top level page items.)
function GetItemIndex(array,item){
for(var i=0;i<array.length;i++){
if(array == item){return i}
}
return null;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks Harbs for your answer. I now know how to determine the stacking index of a pageitem.
However, I am not able to figure out how to change the stacking order of a pageitem - like bring a pageitem to front and so on. I tried changing the order of elements in the pageitems array without much success (may be I'm not doing this right). Also, I see that only Rectangle class has methods like bringForward(), bringToFront() etc. I'm not sure how I can use methods of Rectangle, while I want to work at PageItem level.
Any ideas?
Thanks for your time,
Deepak.
Copy link to clipboard
Copied
PageItem is a base class. Any class that can reside on a page has a bringForward() method. (i.e. Rectangle, Group, Polygon, TextFrame, etc.)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The '.slice(0)' is there to force a duplication of the array.
If it were omitted, InDesign would merely copy a reference to
theRealm.allPageItems, and we'd be no better off.
var realmItems = theRealm.allPageItems.slice(0);
var realmLength = realmItems.length;
for (var idx = 0; idx < realmLength; idx++)
3.6-3.7 (seconds)
t = app.activeDocument.textFrames;
for (i = 0; i < t.length; i++)
if (t instanceof TextFrame) {}
0.06-0.11
t = app.activeDocument.textFrames.everyItem().getElements();
0.06-0.14
t = app.activeDocument.textFrames.everyItem().getElements().slice(0);
2.5-2.6
t = app.activeDocument.textFrames;
t_length = t.length;
for (i = 0; i < t_length; i++)
if (t instanceof TextFrame) {}
0.06-0.14
t = app.activeDocument.textFrames.everyItem().getElements();
0.06-0.12
t = app.activeDocument.textFrames.everyItem().getElements().slice(0);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Further to the speeding up of ExtendScript (see WissenWanne, http://niemannross.com/developer/wiki/index.php?title=JavaScript_tips_and_tricks 😞 I did my original tests against CS2 or CS3 - so some things might have since been optimized in CS4.
The added .slice(0) mentioned in previous posts might not be useful for collections in CS4, but I seem to remember it did make a difference in older versions of InDesign.
But the main reason I used .slice(0) was to remove any 'dynamism' from the returned array - i.e. completely detach the array of elements from the original collection.
Collections are 'live' objects that auto-update all the time to reflect the document structure. Proper primitive arrays are 'dead' - they don't change as a result of changes in the document.
Suppose I grabbed a collection of all items on a particular page, and then started moving these items one by one to other pages.
If I'd rely on the collection, that collection would auto-update as each item is being moved away. If I instead rely on a totally detached array, the array won't change even though elements are 'disappearing' from the collection that I used to initialize the array.
I forgot the exact details, but I remember that without the .slice(0) I still had some 'live link' between the apparent 'array' returned by getElements() and the collection. Using .slice(0) destroyed that (undesirable) live link. I did not really dig deep into that, and the point might have become moot in CS4.
But more importantly, I do remember that using .slice(0) was of great influence when applied to .allPageItems - which is not a collection, but something that pretends to be an array.
Using the .allPageItems.slice(0) made a tremendous difference with older versions of InDesign. Haven't re-tested with CS4 though.
Cheers,
Kris
Copy link to clipboard
Copied
Hi,
What I'm seeing is almost the exact opposite of one of the critical assumptions here!
If I use this;
var pis = container.pageItems.everyItem().getElements ();
Based on what you were saying above, I should see an array with a mix of object types in the correct zOrder.
What I am actually seeing is Rectangles, then Polygons, then TextFrames...
This is based on InDesign CC, so I don't know whether something has changed?
However, more pertinently, is there an efficient way for me to derive the .index value reliably? I am seeing times of 5 minutes+ to interrogate the .index value on a list of page items where a designer copy-pasted vector art as a background...
Thanks,
G
Copy link to clipboard
Copied
"
var pis = container.pageItems.everyItem().getElements ();
Based on what you were saying above, I should see an array with a mix of object types in the correct zOrder.
What I am actually seeing is Rectangles, then Polygons, then TextFrames...
"
I have the same problem with Indesign CC (2017). Did you find a solution for this problem?
EDIT: found solution in this comment: https://forums.adobe.com/message/4091126#4091126
Find more inspiration, events, and resources on the new Adobe Community
Explore Now