8 Replies Latest reply on Apr 29, 2014 1:01 AM by Jump_Over

    Tables inside overset text frames

    schiuma24 Level 1

      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[i].parent;

                          var myWidth = myTextFrame.visibleBounds[3] - myTextFrame.visibleBounds[1];

                  myTables[i].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[x].overflows == true){   

                          alert("There is overset text")

                          }

                      };

        • 1. Re: Tables inside overset text frames
          Jump_Over Level 5

          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[i].parent.constructor.name == "TextFrame"  ==> table is in visible part of text, so you can set the width of this frame

           

          If table[i].parent.constructor.name == "Story"     ==> table is in overset part of text, so you can set the width of story.textContainers[-1]

           

          Jarek

          • 2. Re: Tables inside overset text frames
            Kai Rübsamen Adobe Community Professional

            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[i].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[i].width = myWidth;
            }
            

             

            Can someone tell me, why there are to differernt parent-elements here? Thanks.

            • 3. Re: Tables inside overset text frames
              Jump_Over Level 5

              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

              • 4. Re: Tables inside overset text frames
                schiuma24 Level 1

                thanks! you rock!

                • 5. Re: Tables inside overset text frames
                  Laubender Adobe Community Professional & MVP

                  @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

                  • 6. Re: Tables inside overset text frames
                    Kai Rübsamen Adobe Community Professional

                    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.

                    • 7. Re: Tables inside overset text frames
                      Laubender Adobe Community Professional & MVP

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

                       

                      Exactly.

                       

                      Uwe

                      • 8. Re: Tables inside overset text frames
                        Jump_Over Level 5

                        Hi,

                         

                        @ Kai, thats right.

                        I didn't check textContainers, sorry.

                         

                        Jarek