14 Replies Latest reply on Dec 5, 2012 3:23 PM by romanobstuder

    access to part of a table inside textFrames

    romanobstuder Level 1

      Hi all

      I have a table that runs over many pages. Lets say 10 pages.

      As the script lays out the pages I interogate the page for right or left.

      Under some conditions depending on the number of columns in the table the script needs to change some of the gbounds of the textFrame that contains the part of the table.


      I can not find the correct way to interrogate the table that sits inside a given textFrame.

      Remember I could be on page 7 of a table that started on page 1.


      I have access to the textFrame and I find all the textFrames that the table "breaks" through contain 1 InsertionPoint.


      But from there onwards I am lost at sea...


      myTextFrame.insertionPoints.length  <--- this works


      myTextFrame.insertionPoints.item(0).tables.item(0).columns.length <--- this is not working


      It feels like there is nothing in the TextFrame. Of course I can see the table in ID but when scripting I can not "find" anything in there and I guess this is because the table breaks through many textFrames.


      Can anybody share some light on this?




        • 1. Re: access to part of a table inside textFrames
          கற்பனை (Imagine) Level 3

          you need to mention the InDesign ver and Platform.  so that you getting the reply quickly........

          • 3. Re: access to part of a table inside textFrames
            கற்பனை (Imagine) Level 3

            romanobstuder wrote:


            myTextFrame.insertionPoints.item(0).tables.item(0).columns.length <--- this is not working


            try this


            • 4. Re: access to part of a table inside textFrames
              romanobstuder Level 1

              This is not working.


              I have tried many different methods to get anything from this specific textFrame.

              So far no go.


              I think I need to widen the question a bit.

              What I do not understand is what happens if a table runs over many pages.

              Is it possible to point at frame n and querry anything about the table that happens to runs through?


              I am able to point at the story

                          $.writeln("Parent Story Content: " + previousTextFrame.parentStory.contents);

              but this gives me the complet story which in turn contains many tables

              the other thing I was able to do is getting

                          $.writeln("III_How many insertion points: " + previousTextFrame.insertionPoints.length);

              the number of insertion points

              it turns out there is a different number in many different frames

              many times I do get 1 insertion Point

              this happens on the frames where the "middle" part of a long table happens to go through the text frame

              this is exactly where I would like to probe the table

              but it seams I can not get to it


              I would appreciate an explanation or a pointer to one of the "brake" points of a table when the table is not housed in 1 frame

              Thank you for your comments


              • 5. Re: access to part of a table inside textFrames
                கற்பனை (Imagine) Level 3

                If the one table continue to many pages or flow.  In scripting you may possible to get the table at the starting position i.e where the lengthy table starts from TextFrame.


                try this,....


                • 6. Re: access to part of a table inside textFrames
                  romanobstuder Level 1

                  Hi (Imagine)


                  Thank you very much for your answer.


                              $.writeln("Forum Answer 01, will give the number of tables: " + previousTextFrame.tables.length);


                  I have included the above line, an adaption of your answer, the difference being that it points to the correct textFrame.


                  As the script runs and finds the first frame with some text and one table it gives us the correct answer, the number of tables.

                  on the next and all the following textFrames that contain the flow-on of the first table the answer is 0 every time.


                  Then later into the doc textFrames will give a response > 0.


                  That is the case if there is normal Text followed by yet another table.


                  So the problem seams to be:

                  If a textFrame contains only part of a long table and nothing else, I can not probe it, or at least I only get 0 tables as an answer.

                  This of course implies that I can not querry the table for number of columns.


                  Thank you again


                  • 7. Re: access to part of a table inside textFrames
                    romanobstuder Level 1

                    I should ad that on my travels through the forums I have come through the notion that a table "hangs" of an insertionPoint.

                    As I querried my text frames, on the textFrames that only contain only the flow-through part of a long table, I find exactly 1 InsertionPoint.

                    Is it possible to drill into the "hanging on table" from this InsertionPoint?


                    I have tried character[0] at the InsertionPoint, assuming that the table part is nothing else then 1 Character hanging of the insertionPoint.


                    But I got not further with this idea.


                    If somebody can confirm this generall idea I will spend some more time on trying to drill into whatever sits on the InsertionPoint.


                    Thank you



                    • 8. Re: access to part of a table inside textFrames
                      Marc Autret Level 5

                      Hi Romano


                      I can not find the correct way to interrogate the table that sits inside a given textFrame.


                      I can confirm that this is a complicated topic. (This was one of the most difficult challenges to be solved in a script of mine—IndexMatic—where I need to properly identify pages and/or frames related to text contents, especially table contents.)


                      Basically, what you have to know is that a Table object entirely 'exists' within a Character (U+0016, by the way) and is only 'seen' from the TextFrame which is associated to this character—assumed that there is actually an associated text frame (this is not always the case due to overset contexts.) So, when a Table flows through multiple threaded text frames (F0->F1->...->Fn), only F0 actually 'contains' the Table, while F1..Fn just have no contents, and even no insertion points (F1.insertionPoints.length==0) despite the fact that the table is partially rendered into these frames.


                      From the scripting DOM perspective, TextFrames are just layout components—'page items'— the actual text owners are Stories, Footnotes or Cells, which may, or may not, be rendered into one or several text frames. It took me a long time to understand that layout-oriented components and text-oriented component are completely distinct things.


                      Anyway, given a Text element (e.g. a Character, an InsertionPoint, a TextStyleRange…), you have a magic property that returns the textframe(s), if any, which is/are rendering this element: myTextElement.parentTextFrames. The (misnamed!) parentTextFrames array tell you what frames are involved in rendering the text element whatever the actual text owner. So, if you want to know whether a table cell appears in the layout and where it is rendered, use sth like: myCell.insertionPoints[0].parentTextFrames[0]. The result, if defined, is not the frame that 'contains' the table, but the frame that renders this cell.


                      Now, the reciprocal problem is much more interesting: given a TextFrame, how to know what part of your Table it renders? Well, you have no direct way to get that information, because the TextFrame itself may be absolutely empty (no insertion point). The solution is to reverse your algorithm: store somewhere the ID of the frame you want to study, then traverse the Table cells and get the parentTextFrames from the relevant insertion points. Finally, compare the parentTextFrames IDs with the target ID, and here it is. (An optimisation is to only consider the first cell of each table row, since a row is always entirely rendered in at most one textframe.)




                      • 9. Re: access to part of a table inside textFrames
                        romanobstuder Level 1

                        Hi Marc

                        Oh boy am I glad I asked that question...


                        Thank you very much for your explanation. I can tell you have done some painfull work to get to this.

                        For me, I have spent my last 2 days hitting my head against this brick wall.


                        Just to give you a background

                        I run a A5 size financiall brochure. A little bit of copy and long tables that run from page to page.

                        I never know how long the document is so I create pages untill there is no overflow anymore.

                        Somwhere in the middle I get a large table that runs across the full spread.

                        So I have to make sure I start on the left page and for the time this wide table runs the textframe runs over the spread and the textframe gets pulled up to make sure I can use max. realestate.


                        I have found a solution that works for me; ie I have run some of my data and the layout looks perfect every time.


                        I mentioned that I find exactly one insertionPoint in these frames.


                        I thought I should start with that and run a try loop that is fishing for the table.

                        In case it is not a table the querry will go nowhere.

                        But if it is a table I can find the number of columns and react accordingly.



                                            myCurrentTable = myInsertionPoint.paragraphs.item(0).tables.item(0);           

                                            this.table = myCurrentTable;

                                            this.noOfRows = this.table.rows.length;

                                            this.noOfCols = this.table.columns.length;

                                            $.writeln("Rows: " + this.noOfRows);

                                            $.writeln("Columns: " + this.noOfCols);

                                            if (this.noOfCols > 5){ //We only do this on WIDE tables

                                                myRemoveTheFrameSwitch = 1;

                                                $.writeln("***Switch set to 1");



                        Thank you very much for your explanations again


                        • 10. Re: access to part of a table inside textFrames
                          Ville Järvensivu Level 1

                          Hi Marc, thank you for your answer for Romano's question.


                          I stumbled into weird stuff in multipage-tables and getting index in which page specific cell is.

                          Wondering if doing something wrong here..


                          With InDesign document with one table running into three pages:


                          #target indesign

                          var myDoc = app.activeDocument;

                          var myTable = myDoc.pages[0].textFrames[0].tables[0]

                          alert("page.index: " + myTable.rows[60].cells[0].insertionPoints[0].parentTextFrames[0].parentPage.index + "\npage.name: " + myTable.rows[60].cells[0].insertionPoints[0].parentTextFrames[0].parentPage.name)


                          index is allways returned 0, and name is correct..?



                          kaappaus 2012-12-05 at 10.30.55.png

                          kaappaus 2012-12-05 at 10.29.17.png

                          • 11. Re: access to part of a table inside textFrames
                            Marc Autret Level 5

                            Hi Ville,


                            > index is allways returned 0, and name is correct.


                            Because page.index refers to the index of the page within its containing spread.

                            So page.index==0 is correct for page.name=='2' in your example.




                            • 13. Re: access to part of a table inside textFrames
                              [Jongware] Most Valuable Participant

                              Ville, in that case you might be interested to hear about the Page property documentOffset


                              (Relying on page.name is okay as long as your pages are numbered. But if you have roman numbered pages, for example, you can no longer use page.name for any mathematical stuff.)

                              • 14. Re: access to part of a table inside textFrames
                                romanobstuder Level 1

                                Hi all

                                and hi Ville. Have you solved your problem?
                                I had coded this some time ago. Let me know if you are still stuck. Might give you my 5 cent...