Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I dragged to select the cell. Is there another way to get the text frame?

Guide ,
Oct 15, 2025 Oct 15, 2025

My current code looks like this, where I'm using 'item.parent.parent'.

but it feels a bit clunky.


Is there a better way to access `parentTextFrames[0]`?

var item = app.selection[0];
if (item.constructor.name == “Cell”) {
var textFrame = item.parent.parent;
}

 

dublove_1-1760530266055.jpeg

 

TOPICS
How to , Scripting
97
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2025 Dec 02, 2025

Hi, 

 

I don't believe there is a better way to get there, although it is worth noting that you may want to add a check to make sure you have what you think you have, as it is possible for there to be levels of nesting in a table, so just assuming .parent.parent gets you to you the Text Frame may result in issues, depending on what you code is doing

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2025 Dec 02, 2025

Hi @dublove , item.parent.parent would not always work—you could have a table inserted into a cell:

 

var s = app.selection[0];
alert(s.parent.parent.parent.parent)

 

Screen Shot 18.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2025 Dec 02, 2025
LATEST

If there's a chance the cell is in a nested table then you can use a while statement:

 

var s = app.selection[0];
if (s.constructor.name == 'Cell') {
    b = s.parent
    while (b.constructor.name != "TextFrame") {
        b = b.parent   
    }
}

alert(b.constructor.name)

 

 

Screen Shot 19.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines