Skip to main content
dublove
Legend
Jul 28, 2026 11:41 AM UTC
Answered

How to obtain the 'current text box' where the input image is located?

Hi everyone.

I have selected all the content of the article and want to control the embedded images, so I need to obtain the text box where the images are located.
Surprisingly, The parent of the character  is “Story”, not “TextFrame”.

And parentTextFrames [0] may not necessarily be the text box where the image is located, It refers to the first text box that appears to be the story.

How can I get the current textFrame for 'story. allGraphics [i]'?

Thank you.

var d = app.documents[0];
var item = d.selection[0]
var story = item.parent;

if (story.allGraphics.length > 0) {
for (var i = 0; i < story.allGraphics.length; i++) {
var curFrame = story.allGraphics[i].parent.parent.parentTextFrames[0];
alert(curFrame.constructor.name);
}
}

 

    Manan JoshiCorrect answer
    Community Expert
    Jul 28, 2026 12:00 PM UTC

    The character would have parentTextFrames property. It is an array, so you would access it as parentTextFrames[0]

    Do place proper check because if the image is on overset text this array may be empty. You might have to do special handling for image inside table cell

    -Manan

    14 replies

    Manan JoshiCommunity ExpertCorrect answer
    Community Expert
    Jul 28, 2026 12:00 PM UTC

    The character would have parentTextFrames property. It is an array, so you would access it as parentTextFrames[0]

    Do place proper check because if the image is on overset text this array may be empty. You might have to do special handling for image inside table cell

    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    Jul 28, 2026 1:06 PM UTC

    Hi ​@Manan Joshi 

    But parentTextFrames [0] refers to the first text box, but not necessarily the text box where the current image is located.

    Or is parentTextFrames [0] the current one?

     

    Translate
    Community Expert
    Jul 28, 2026 1:14 PM UTC

    No it does not. Test it once

    Translate
    -Manan