Skip to main content
dublove
Legend
Nov 15, 2026 10:51 AM UTC
Answered

How to obtain the images and geometric shapes outside the text box of the entire document when nothing is selected?

Hello everyone.

As shown in the picture, how to obtain the three objects on the right when nothing is selected?

The following is the code I tried to obtain images for, but found that I could only get one image.

It should be the nested one that was not obtained

var d = app.activeDocument;
var item = d.selection[0];
if (item == undefined) {
ag = d.allGraphics;
}
var ot = [];
for (var i = 0; i < ag.length; i++) {
if (ag[i].parent.parent.constructor.name == 'Spread') {
ot.push(ag[i]);
}
}
alert(ot.length);
var api = d.allPageItems;
var pi = d.pageItems;

 

    rob day
    rob dayCorrect answer
    Community Expert
    Nov 15, 2026 3:13 PM UTC
    var pi = app.activeDocument.pageItems.everyItem().getElements()
    for (var i = 0; i < pi.length; i++){
    //get page items that are not textframes
    if (pi[i].constructor.name != "TextFrame") {
    alert(pi[i])
    }
    };

     

    5 replies

    rob day
    Community Expert
    Community Expert
    Nov 15, 2026 1:32 PM UTC

    If the anchored object is a group with an image inside, the example wouldn’t skip the nested image. In that case you would need a while statement to check for a character parent.

    Translate
    rob day
    Community Expert
    Community Expert
    Nov 15, 2026 12:52 PM UTC

    Something like this gets images that are not anchored in text:

     

    var api = app.activeDocument.allPageItems

    for (var i = 0; i < api.length; i++){
    //get all images that are not anchored in text
    if (api[i].constructor.name == "Image" && api[i].parent.parent.constructor.name != "Character") {
    alert("Image on page: " + api[i].parentPage.name)
    }
    };

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Nov 15, 2026 2:51 PM UTC

    Hi ​@rob day 

    I am referring to objects outside the text box.
    You didn't understand what I meant. What I meant was how to retrieve all objects outside the text box.
    (No object selected)Just like I chose these three objects:
    sel=d.selection;
    I can obtain them using sel [0] sel [1] sel [2].

     

    Translate
    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    Nov 15, 2026 3:13 PM UTC
    var pi = app.activeDocument.pageItems.everyItem().getElements()
    for (var i = 0; i < pi.length; i++){
    //get page items that are not textframes
    if (pi[i].constructor.name != "TextFrame") {
    alert(pi[i])
    }
    };

     

    Translate