Skip to main content
dublove
Legend
March 22, 2026
Question

How does the script determine whether an image is outside the text box or positioned inside it?

  • March 22, 2026
  • 2 replies
  • 53 views

Does “parentTextFrames” refer to the immediate parent or the outermost level?
Is it possible to check whether a text frame exists at the outermost level, regardless of the currently selected layer?

I’m currently using the method below to check, but it feels a bit clunky—sometimes I need multiple parents.
Is there a simpler way to do this?

Also, how can I distinguish between images and rectangular frames?
Often, they’re both called “Rectangle.”
Should I check for the presence of an “image” property?

Thanks.

Some thing like this:

var doc = app.activeDocument;
var item = doc.selection[0]; 
var items = doc.selection;

//outside 
    if (
        (gra && 'Spread' == item.parent.constructor.name)

        && ('Rectangle' == item.constructor.name)
    ) {
        sel = items;
do….
        }
        exit();
    }

 

    2 replies

    stuart012broad
    Participant
    March 23, 2026

    Hello,

    parentTextFrames only gives the immediate parent, so to find the outermost frame you need to loop up until the parent is a Spread or Page. Once you reach that level, you know the frame is at the outermost layer. To distinguish rectangles from images—since both have Rectangle as their type eplfeedback check the .images.length property: if it’s greater than zero, it contains an image; otherwise, it’s just a shape.

    Community Expert
    March 22, 2026

    If an image is inside a textframe, i.e. it is an anchored image then its parent should be a character. So something like

    item.parent.constructor.name === “Character”

    or

    item.parent.parent.constructor.name === “Character”

    Depending upon if item is the image or the rectangle

    -Manan
    Community Expert
    March 22, 2026

    Just to run by you - you don’t need to climb multiple parents manually.

    Anchored objects always have a Character somewhere in their parent chain, so a simple loop checking instanceof Character would be enough wouldn’t it?

    Also, for distinguishing images vs rectangles  they’re all Rectangle, so just check item.graphics.length > 0.

    I’d say that might be simplest and most reliable approach, what do you think?

    dublove
    dubloveAuthor
    Legend
    March 22, 2026

    Thanks, I almost forgot about this:
    item.graphics.length > 0