Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Tables inside overset text frames

Explorer ,
Apr 28, 2014 Apr 28, 2014

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")

                    }

                };

TOPICS
Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Apr 28, 2014 Apr 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

...
Translate
Mentor ,
Apr 28, 2014 Apr 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 28, 2014 Apr 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 28, 2014 Apr 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 28, 2014 Apr 28, 2014

thanks! you rock!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2014 Apr 28, 2014

@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:

ThreadedTextFramesWithTableOverset.png

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

AfterScript_AddressingFirstTextFrameForWidth.png

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:

AfterScript_AddressingLastTextFrameForWidth.png

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 29, 2014 Apr 29, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2014 Apr 29, 2014

It seems, that story.textContainers[-1] does not work, because of textContainers is an array?!

Exactly.

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 29, 2014 Apr 29, 2014
LATEST

Hi,

@ Kai, thats right.

I didn't check textContainers, sorry.

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines