Skip to main content
dublove
Legend
March 29, 2026
Answered

How to I refer to the outermost text Frame?

  • March 29, 2026
  • 3 replies
  • 42 views

It didn't turn over again.

I have a text box A that contains another text box B. I have currently selected B, meaning that the current item is B. How do I refer to A?

var doc = app.activeDocument;
var item = doc.selection[0]; // Current selected item
var items = doc.selection; // All currently selected items

var B = item;
var A = item.parent.parent;
var A2=item.parent.parentTextFrames;
alert(A);

The result is [object Story]
How do I convert this to a text frame?

Is this it? item.parent.parentTextFrames;
But it seems like my function isn't responding.

Thank you.

 

    Correct answer dublove

    Thank you.
    I figured it out—it turns out to be this:

    item.parent.parentTextFrames[0];

     

    3 replies

    Community Expert
    March 29, 2026

    app.selection[0].parent.parentTextFrames[0] should give you frame A

    So, if app.selection is a frame that is anchored in another textframe , its parent is a character.and character has parentTextFrames property

    -Manan
    dublove
    dubloveAuthorCorrect answer
    Legend
    March 29, 2026

    Thank you.
    I figured it out—it turns out to be this:

    item.parent.parentTextFrames[0];

     

    dublove
    dubloveAuthor
    Legend
    March 29, 2026

    @m1b 

    I just realized:
    It looks like I'm stuck again with the issue of not being able to retrieve the outermost text frame:
    var textFrame = getTextFrames(items)[0];

    rob day
    Community Expert
    Community Expert
    March 29, 2026

    Hi ​@dublove , I would use a while statement for something like this because the selected text frame could be nested any number of levels deep (see attached):

     

    //a selected anchored text frame
    var s = app.activeDocument.selection[0];
    //an anchored text frame’s parent is a character
    var p = s.parent;
    //the outside text frame to get
    var otf;
    if (p.constructor.name == "Character") {
    while (p.constructor.name == "Character") {
    //the character’s first parentTextFrame
    otf = p.parent.texts[0].parentTextFrames[0]
    //p returns as a character until the outer text frame
    p = p.parentTextFrames[0].parent
    }
    }
    //move the text frame
    otf.move([0,0])
    alert("First Word: " + otf.words[0].contents)