Skip to main content
dublove
Legend
Mar 29, 2026 7:47 AM UTC
Answered

How to I refer to the outermost text Frame?

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.

 

    rob day
    rob dayCorrect answer
    Community Expert
    Mar 29, 2026 2:19 PM UTC

    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)

     

    11 replies

    Community Expert
    Mar 29, 2026 11:17 AM UTC

    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

    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    Apr 7, 2026 5:15 AM UTC

    ​@m1b 

    When a text box contains other text frames.
    How can I use `var textFrame = getTextFrames(items)[0];` to retrieve the outermost text box?
    Currently, it retrieves the small purple box.

     

    Translate
    Community Expert
    Apr 7, 2026 7:18 AM UTC

    ​@dublove what is this getTextFrames function I am not sure I am seeing its definition in this post. However, the code that ​@rob day should work for you, You never replied to him or me but are addressing ​@m1b who has not even written on this thread and referring to a function not even discussed.

    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    Mar 29, 2026 11:08 AM UTC

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

    item.parent.parentTextFrames[0];

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Mar 29, 2026 8:11 AM UTC

    ​@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];

    Translate
    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    Mar 29, 2026 2:19 PM UTC

    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)

     

    Translate
    dublove
    dubloveAuthor
    Legend
    Apr 7, 2026 3:15 PM UTC

    Hi ​@rob day 

    Thanks, it really works well.

    What if the cursor is in any state within the table?
    For example: in text, in a cell, selecting text, selecting a cell, selecting a row, selecting a table.
    Can you retrieve the outermost TextFrame using a simple code?

    Translate