Skip to main content
Inspiring
April 28, 2014
Answered

Tables inside overset text frames

  • April 28, 2014
  • 2 replies
  • 1209 views

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.overflows == true){   

                    alert("There is overset text")

                    }

                };

This topic has been closed for replies.
Correct answer Kai Rübsamen

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.

2 replies

Kai Rübsamen
Kai RübsamenCorrect answer
Participating Frequently
April 28, 2014

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.

Jump_Over
Legend
April 28, 2014

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

Jump_Over
Legend
April 28, 2014

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