Skip to main content
daitranthanhoa
Inspiring
August 23, 2023
Question

How can get parentTextFrame of a Cell was Overflow?

  • August 23, 2023
  • 3 replies
  • 789 views

I have a Table put in Link Frame:

 

I want get Parent TextFrame of Cells in Link Frame 2:

If Cell is not overflow, i can get by code:

oCell.texts(1).insertionPoints(1).parentTextFrames(1)

 

But If Cell overflow, above code can't get Parent TextFrame.

How can get parentTextFrame of a Cell was Overflow?

This topic has been closed for replies.

3 replies

Community Expert
August 23, 2023

Nice one, Mark. Maybe if you recompose the cell after removing the zero-width space it'll go back to its original state.

m1b
Community Expert
Community Expert
August 23, 2023

Thanks @Peter Kahrel, it didn't work in this case because the "original state" was incorrect. See my comment above. - Mark

m1b
Community Expert
Community Expert
August 23, 2023

Hi @daitranthanhoa, I have written a function that gets this. Here you go:

 

/**
 * Return a cell's parent text frame.
 * @author m1b
 * @version 2022-08-18
 * Note: getting the parent text frame is a challenge when
 * there are no insertion points due to overset text, so
 * here we add a zero-width space as the first character
 * therefore the first insertionPoint will now be active
 * @param {Cell} cell - an Indesign Table Cell.
 * @returns {TextFrame}
 */
function getParentTextFrame(cell) {

    if (!cell.isValid)
        return;

    // insert zero-width space to expose first
    // insertion point in case where cell is overset
    cell.insertionPoints[0].contents = '\u200B';

    // get the text frame
    var textFrame = cell.insertionPoints[0].parentTextFrames[0];

    // clean up
    cell.characters[0].remove();
    cell.recompose();

    if (
        textFrame != undefined
        && textFrame.isValid
    )
        return textFrame;

};

Edit 2023-08-23: as per @Peter Kahrel's great suggestion, I added cell.recompose() after removing the zero-width space. This did make a slight difference when I tested on every cell of @daitranthanhoa sample document (see attached).

 

Community Expert
August 23, 2023

Brilliant idea @m1b, never thought of this use of Zero-Width Space

-Manan

m1b
Community Expert
Community Expert
August 23, 2023

Thank you @Manan Joshi 😀

 

I should point out that this won't help if the *whole* cell is overset, because in that case it doesn't have a parent text frame.

Willi Adelberger
Community Expert
Community Expert
August 23, 2023

What do you want to afford with a table on the master/parent page? As content should not be there.