Copy link to clipboard
Copied
Hi everybody!
Im trying to write a script to set the width of all tables in a document equal to its parent text frame, I was succesful, but
the tables that are overflowed do not get resized. I have only come up with a way to find if there is an overflowed text frame
but not to find and overflowed text frame contents. PLS HELP!
heres my code:
//resizes tables
var myTextFrames = app.activeDocument.textFrames.everyItem();
var myTables = myTextFrames.tables.everyItem().getElements();
for (var i = 0; i < myTables.length; i++){
var myTextFrame = myTables.parent;
var myWidth = myTextFrame.visibleBounds[3] - myTextFrame.visibleBounds[1];
myTables.width = myWidth;
};
//finds a textframe with overset text
var myOverset = app.activeDocument.textFrames.everyItem().getElements();
for(var x = 0; x < myOverset.length; x++){
if(myOverset
alert("There is overset text")
}
};
Hi,
I’m not sure, if I understand the goal correctly: You try to set the width of a table that is not visible, because the textframe overflows or because elements of the table overflows?
If the first one is the case: It seems that the parent of a visual text is a textframe. But the parent of a non visible table is a story. If you try story.textFrames[0] the length == 0, but if you try story.textContainers[0] you get an result.
Does that help?
...//resizes tables
var myTables = app.activeDocument.stories
Copy link to clipboard
Copied
Hi,
Are your stories going through various wide textFrames?
To work with stories instead of textFrames points you to each story.table, even overset ones.
I mean:
var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
If table.parent.constructor.name == "TextFrame" ==> table is in visible part of text, so you can set the width of this frame
If table.parent.constructor.name == "Story" ==> table is in overset part of text, so you can set the width of story.textContainers[-1]
Jarek
Copy link to clipboard
Copied
Hi,
I’m not sure, if I understand the goal correctly: You try to set the width of a table that is not visible, because the textframe overflows or because elements of the table overflows?
If the first one is the case: It seems that the parent of a visual text is a textframe. But the parent of a non visible table is a story. If you try story.textFrames[0] the length == 0, but if you try story.textContainers[0] you get an result.
Does that help?
//resizes tables
var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
for ( var i = 0; i < myTables.length; i++ ){
var container = myTables.parent;
if ( container.constructor.name == "TextFrame" ) {
var myTextFrame = container;
}
else if ( container.constructor.name == "Story" ) {
var myTextFrame = container.textContainers[0];
}
var myWidth = myTextFrame.visibleBounds[3] - myTextFrame.visibleBounds[1];
myTables.width = myWidth;
}
Can someone tell me, why there are to differernt parent-elements here? Thanks.
Copy link to clipboard
Copied
Kai Rübsamen wrote:
...Can someone tell me, why there are to differernt parent-elements here?...
Each object (child) suppose to have a parent. Basically for tables textFrame is a parent but sometimes they go wild, I mean they reduces their custody - in this case a story becomes responsible for...
Table's life is brutal ![]()
Jarek
Copy link to clipboard
Copied
thanks! you rock!
Copy link to clipboard
Copied
@Kai – cool. Maybe just a little thing:
You suppose that the first text frame of a given story has the same width as the one with the overset (holding a table in the overflow).
So, if we have the following situation:

A table in the overflow will get too wide after running your script:

Instead of the first text frame in the story we could address the last one directly with:
else if ( container.constructor.name == "Story" ) {
var myTextFrame = container.textContainers[0].endTextFrame;
}
And the result will be:

The property endTextFrame is in the class of TextFrame.
We could also have written:
else if ( container.constructor.name == "Story" ) {
var myTextFrame = container.textContainers[container.textContainers.length-1];
}
Uwe
Copy link to clipboard
Copied
Hi Guys,
thanks for your response. Verry helpful to me
.
@ Jarek: It seems, that story.textContainers[-1] does not work, because of textContainers is an array?!
@ Uwe: I thought to myself, that the first frame won’t be the right one in every case, but then I went to bed
. Nevertheless I did not know endTextFrame and find also previousTextFrame, nextTextFrame and startTextFrame, cool.
Copy link to clipboard
Copied
It seems, that story.textContainers[-1] does not work, because of textContainers is an array?!
Exactly.
Uwe
Copy link to clipboard
Copied
Hi,
@ Kai, thats right.
I didn't check textContainers, sorry.
Jarek
Find more inspiration, events, and resources on the new Adobe Community
Explore Now