Skip to main content
dublove
Legend
Nov 13, 2026 4:41 AM UTC
Answered

Can we put all the images, Rectangle, Oval, Polygon, and Graphline in the selection into one collection?

I have selected some text that may contain images Rectangle、Oval、Polygon、Graphicline。
I don't want to distinguish what these objects are, I want to push them all into one collection.

I want to use for to traverse them in the future. Can it be achieved?

like this:

var d = app.activeDocument;
var sel= d.selection;
var s= d.selection[0];
var ob=[ob0,ob2,ob3.....]

for(var i=0;i<ob.length;i++){
ob[i]
}

 

    rob day
    rob dayCorrect answer
    Community Expert
    Nov 13, 2026 12:50 PM UTC

    How to check the type of pageItems [0], such as constructor. name. 

    Now I understand pageItems and allPageItems

     

    It’s important to note that allpageItems is an array while pageItems is a collection. You can convert a collection into an array with getElements, but it would not include the images inside of the rectangles.

     

    If I run this code the 2 images are not included in the page items collection, but they are in the all page items array:

     

    var s = app.selection[0];
    var api = s.allPageItems
    var pi = s.pageItems
    alert(pi.length + " page items: \r" +pi.everyItem().getElements())
    alert(api.constructor.name + " with " + api.length + " items: \r" + api)

     

     

    8 replies

    Community Expert
    Nov 13, 2026 4:54 AM UTC

    If your selection is the textframe containing all these elements then the following code will give you the collection of the pageItems

    app.selection[0].pageItems

     

    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    Nov 13, 2026 6:42 AM UTC

    That's what it means.
    Thanks.
    Now I understand pageItems and allPageItems

    Translate
    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    Nov 13, 2026 12:50 PM UTC

    How to check the type of pageItems [0], such as constructor. name. 

    Now I understand pageItems and allPageItems

     

    It’s important to note that allpageItems is an array while pageItems is a collection. You can convert a collection into an array with getElements, but it would not include the images inside of the rectangles.

     

    If I run this code the 2 images are not included in the page items collection, but they are in the all page items array:

     

    var s = app.selection[0];
    var api = s.allPageItems
    var pi = s.pageItems
    alert(pi.length + " page items: \r" +pi.everyItem().getElements())
    alert(api.constructor.name + " with " + api.length + " items: \r" + api)

     

     

    Translate