Copy link to clipboard
Copied
I am trying to determine if text frames or cells in a table have overset text using .overflows. I was under the impression that a table overflow could be determined using table.overflow, but it seems to give me unexpected results. Is it possible that this property is no longer reliable, or perhaps it is not capable of checking overflow in the celluar level? I am using UXP with the InDesign DOM.
I think I was under the impression that I could use textframe.overflows to determine if a table had overset text.
I can‘t help with UXP, but with JS, the cell itself can have an overflow, or it can contain a textframe with an overflow. Here‘s a JS example:
var c = app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().getElements()
var s = "Overflows:\r"
for (var i = 0; i < c.length; i++){
//true if the cell itself has a text overflow
if (c[i].overflows) {
Gotcha, okay so it seems that there is no way to check if any cell on a table has overflow without checking each cell's overflow property. Otherwise, you are checking the overflow of the text frame, which is not quite the same scenario. Alright, that makes sense. Thank you for clarifying.
Copy link to clipboard
Copied
What do you see in the InDesign?
Copy link to clipboard
Copied
Sometimes it helps to check with “properties”, e.g.
Cell.properites.overflows
or using
Cell.recompose()
Copy link to clipboard
Copied
Hi @MahmoodTheDoom , Are you sure there are no text frames nested in the cells? With JavaScript the first cell in this table returns .overflows as true, but the 2nd cell returns false because the overflow is in a textframe pasted into the cell, not the cell itself:
Copy link to clipboard
Copied
I think I was under the impression that I could use textframe.overflows to determine if a table had overset text. That does not seem to be the case after testing this property a bit. If I had a table with cells that could have overset text, the only way to determine that is to loop through each cell and check the cell.overflows property. Is that correct?
I tried using the story, but that does not seem to work.
Copy link to clipboard
Copied
I think I was under the impression that I could use textframe.overflows to determine if a table had overset text.
I can‘t help with UXP, but with JS, the cell itself can have an overflow, or it can contain a textframe with an overflow. Here‘s a JS example:
var c = app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().getElements()
var s = "Overflows:\r"
for (var i = 0; i < c.length; i++){
//true if the cell itself has a text overflow
if (c[i].overflows) {
s+="Cell " + c[i].index + " has overflow text\r"
}
//true if the cell contains a text frame
if (c[i].textFrames.length) {
//true if the text frame has an overflow
if (c[i].textFrames[0].overflows) {
s+="Cell " + c[i].index + " contains a text frame with overflow text\r"
}
}
};
alert(s)
Here the first cell has an overflow, and the 2nd cell has a text frame with an overflow.
I have to check if there are text frames in the cells:
Copy link to clipboard
Copied
Gotcha, okay so it seems that there is no way to check if any cell on a table has overflow without checking each cell's overflow property. Otherwise, you are checking the overflow of the text frame, which is not quite the same scenario. Alright, that makes sense. Thank you for clarifying.
Copy link to clipboard
Copied
Table doesn't have overflows property, so you need to check every Cell.
@rob day provided great example - but I would change one thing - instead of checking only FIRST TF of each Cell - used everyItem() to get all TFs from all Cells - just in case 2nd, 3rd, Nth has overflow.
Copy link to clipboard
Copied
everyItem() to get all TFs from all Cells - just in case 2nd, 3rd, Nth has overflow.
Also, there could be any number of nested textframes, so getting every text frame might not work. Would be better to get allPageItems and check the array for a text frame with an overflow.
var c = app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().getElements()
var s = "Overflows:\r"
var api;
for (var i = 0; i < c.length; i++){
//true if the cell itself has a text overflow
if (c[i].overflows) {
s+="Cell " + c[i].index + " has overflow text\r"
}
api = c[i].allPageItems
//true if the cell contains a page item
if (api.length) {
for (var j = 0; j < api.length; j++){
//the page item is a text frame with an overflow
if (api[j].constructor.name == "TextFrame" && api[j].overflows) {
s+="Cell " + c[i].index + " contains a text frame with overflow text\r"
}
};
}
};
alert(s)
Copy link to clipboard
Copied
So we could do it like that?
var TFs = app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().allPageItems.everyItem().getElements()
Copy link to clipboard
Copied
.allPageItems is not a collection it’s an array, so it will not take .everyitem()
Copy link to clipboard
Copied
.allPageItems is not a collection it’s an array, so it will not take .everyitem()
By @rob day
So in JS it's not the same type as .pageItems?
Copy link to clipboard
Copied
Right it‘s an array, and arrays don’t have a collection’s everyItem() method. Your code throws this error:
.pageItems is a collection and can use the everyItem() method but it wouldn’t get nested frames—this kind of thing is the reason for the .allPageItems property:
Copy link to clipboard
Copied
Thanks. A bit strange - both should be collections?
Will this work - I'm on my phone - myTable.pageItems or myTable.allPageItems - instead of everyItem()?
Copy link to clipboard
Copied
It’s designed as a shortcut. Consider this case where cell 1 contains 5 page items:
.pageItems.everyItem() returns just the one text frame, while .allPageItems returns an array of everything inside the cell’s text frame
var pi = app.documents[0].stories.everyItem().tables.everyItem().cells[0].pageItems.everyItem().getElements();
$.writeln(pi)
//returns [object TextFrame]
var api = app.documents[0].stories.everyItem().tables.everyItem().cells[0].allPageItems;
$.writeln(api)
//returns [object TextFrame],[object Group],[object Oval],[object TextFrame],[object TextFrame]
Copy link to clipboard
Copied
I know what is the difference between pageItems and allPageItems - 1st is just a "first level" and 2nd is "all, even if part of the group, etc." - why in both cases it can't be a collection? It's returned "flat" anyway.
In my tool - written in VisualBasic - I'm declaring my variable as Variant - then, depends on if user wants 1st level or all - set 1st or 2nd - the rest of the code remains exactly the same - and I don't even have to care from what object I'm "extracting" those collections.
Copy link to clipboard
Copied
Hi @MahmoodTheDoom ,
be aware, that there is another kind of visual indicator that an "overflow" will very likely occur if you add contents with e.g. cell.contents = "String" to a table's text cell. The end of story marker is not showing when the cell is on fixed height and the point size of the first insertion point exceeds a certain value:
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Very good point! We currently utilize these indications, but we wanted to create a script that could easily check all tables in case someone missed a text frame 🙂
Copy link to clipboard
Copied
Very good point! We currently utilize these indications, but we wanted to create a script that could easily check all tables in case someone missed a text frame 🙂
By @MahmoodTheDoom
You can use Preflight for that:
2nd cell has a TF inside - 3rd has a text bigger than available height - but there is a red dot - to the contrary of what @Laubender suggested?
Copy link to clipboard
Copied
But it doesn't show TextFrame's overset - when Cell is already overset:
Which is rather OK - as TF in an overset Cell - doesn't have GeometricBounds anyway.