There are a couple of things worth discussing here.
First, your screenshot shows the row height set to Exactly 30 pt. This is a fixed height, rather than InDesign's calculated minimum height.
Your formula of `4 + 14 + (2 × 1.417) doesn't quite reflect how InDesign composes text. Two lines with 14 pt leading have a 14 pt distance between their baselines. The remaining height depends on font metrics, the first baseline offset, the cell insets and potentially other formatting.
Also, the cell containing the most lines isn't necessarily the cell that determines the required row height. A cell with fewer lines but larger text, different leading or larger insets could require more height.
For scripting, you can use
cell.lines.length
to count the composed lines in each cell
and
row.height
to obtain the actual row height
On your other question
InDesign provides
table.height
which gives the total height of the table.
You can also use
table.columns[0].height
or sum the heights of the individual rows
However, if you're asking for the height of only the portion of a table displayed in the current text frame, that is a different calculation. You would need to identify the rows composed in that frame and sum their heights. If the frame contains multiple text columns, you would also need to distinguish between those columns.
Here’s a quick example that reports the cell or cells containing the most composed lines, the actual row height and the table height.
Let us know where we go from here :)
(function () {
if (!app.documents.length || !app.selection.length ||
app.selection[0].constructor.name !== "Cell") {
alert("Please select a single table cell.");
return;
}
var cell = app.selection[0];
var row = cell.parentRow;
var table = row.parent;
var maxLines = -1;
var longestCells = [];
// Find cells with the most composed lines
for (var i = 0; i < row.cells.length; i++) {
var count = row.cells[i].lines.length;
if (count > maxLines) {
maxLines = count;
longestCells = [i + 1];
} else if (count === maxLines) {
longestCells.push(i + 1);
}
}
var report =
"Most lines: " + maxLines +
"\nCell number(s): " + longestCells.join(", ") +
"\nActual row height: " + row.height +
"\nWhole table height: " + table.height;
// Sum rows belonging to the selected cell's text frame
var frames = cell.insertionPoints[0].parentTextFrames;
if (frames.length > 0) {
var frame = frames[0];
var frameHeight = 0;
var rowsFound = 0;
for (var r = 0; r < table.rows.length; r++) {
var firstCell = table.rows[r].cells[0];
var rowFrames =
firstCell.insertionPoints[0].parentTextFrames;
if (rowFrames.length > 0 &&
rowFrames[0].id === frame.id) {
frameHeight += table.rows[r].height;
rowsFound++;
}
}
report +=
"\nRows detected in current frame: " + rowsFound +
"\nTheir combined height: " + frameHeight;
}
alert(report);
})();