Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now