8 Replies Latest reply on Feb 20, 2014 2:58 PM by gisteppen

    How to access a table for changes

    gisteppen Level 1

      I'm iterating through the Pgf objects in a flow, and for each one I look for table anchors. I find the table anchor, then what do I do to access its Tbl object and do things with it? I'm just trying to find out if there are any changebars in the table. I don't think using Doc.FirstTblInDoc will help me because I'm starting with a TblAnchor text item.

       

      I run this code on a doc that has only one paragraph with a table anchor in it:

       

      function test() {

          doc = app.ActiveDoc;

          var pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

          while ( pgf.ObjectValid() ) {

          var textitems = pgf.GetText(Constants.FTI_TblAnchor);

          var aa = textitems[0];

          Console('what is this: '+aa);

          pgf = pgf.NextPgfInFlow;

          }

      }

       

      This prints "what is this: [object TextItem]".

       

      Seems like I should be able to do something like this to get the Tbl object:

       

      myTable = textitems[0].idata;

       

      Am I warm? Once I get the Tbl object, I'm hoping it's a simple matter of using GetText to get changes, then finding a changebar.

       

      Thanks,

      Mark

        • 1. Re: How to access a table for changes
          frameexpert Level 4

          This should give you the Tbl (table) object:

           

          myTable = textItems[0].obj;
          
          • 2. Re: How to access a table for changes
            Russ Ward Level 4

            Rick, interesting. I would have thought to use .idata. For .idata, the documentation says:

             

            ID of the object if the text item is an object,.

             

            ...then it says something cryptic for .obj. Seems I've used .idata in the past for objects. But I could be wrong, just pointing this out.

             

            Mark, once you have the table object, you'll need to iterate over each cell and execute getText() on each. You can't get the text for a whole table at once.

             

            Russ

            1 person found this helpful
            • 3. Re: How to access a table for changes
              frameexpert Level 4

              Hi Russ, I just checked some of my code and it is obj. Here is how I navigate all of the tables in the document's main flow:

               

              var tbl = 0, textList = 0, i = 0;
              
              textList = doc.MainFlowInDoc.GetText(Constants.FTI_TblAnchor);
              for (i = 0; i < textList.length; i += 1) {
                tbl = textList[i].obj;
                // Process the table here.
              }
              
              • 4. Re: How to access a table for changes
                Russ Ward Level 4

                Thanks Rick. I guess the documentation is a bit unclear (shocker!). In defense of the documentation, though, I recognize it is a major task to document such a huge interface. I think the first issue was OK regarding the size of the task, but it does seem that it has stalled a bit as far as improvement.

                 

                Russ

                • 5. Re: How to access a table for changes
                  4everJang Level 3

                  FYI, I am working on a user-friendly (or developer-friendly) documentation in the shape of a website. I have noted the info about the table object, as well as other errors and omissions I have found myself. Once the site is reasonably finished, I will announce it here, of course.

                   

                  Ciao

                   

                  Jang

                  • 6. Re: How to access a table for changes
                    frameexpert Level 4

                    There are two approaches they could have used: 1) Make a copy of the FDK docs and modify them for ExtendScript. That would have at least given a good overview and provided some examples. 2) Have a "community" project, like a wiki, and open it up to the community at large. Right now, things are scattered: I have information from my webinars, Debra Herman has her useful blog (http://extendingframemaker.blogspot.com/), there is good information here. I am curious about what Jang is doing.

                    • 7. Re: How to access a table for changes
                      4everJang Level 3

                      Hi Rick,

                       

                      I have seen Deba Herman's blog but it has been virtually dead for almost two years now. I can understand that, as my own blog has been in a 'restful' state for a while now. I would be interested in having a number of people cooperate on building a truly useful site, but I am steering clear of a Wiki, as there are lots of usability issues I see with it. One obvious thing is that I am creating 'automagical' progressive disclosure in the web pages, which I do not see happening with a standard Wiki.

                       

                      Anyway, as aoon as I have a first version ready - hopefully soon - I will let you guys know and I will be interested in receiving your feedback.

                       

                      Ciao

                       

                      Jang

                      • 8. Re: How to access a table for changes
                        gisteppen Level 1

                        Here's the working code I ended up using to search through a table and find out if it had any changebars.

                         

                        Mark

                         

                        // Find a changebar in tables. The context is iterating through the Pgfs in a doc.
                        function findChangebarInTable(pgf) {
                            var tableitems = pgf.GetText(Constants.FTI_TblAnchor);
                            // If no table anchors, return now.
                            if (tableitems.length == 0) { return; }
                            for (var i = 0; i < tableitems.length ; i += 1) {
                                // get table using table anchor.
                                var table = tableitems[i].obj;
                                cellChangebar = searchCells(table);
                                // If there's a changebar in any table, return.
                                if (cellChangebar) {
                                    return true;
                                }
                            }
                        }

                         

                         

                        // Search the cells of the table for a changebar.

                        function searchCells(table) {

                            var tcell = table.FirstRowInTbl.FirstCellInRow;

                            while (tcell.ObjectValid()) {

                                // Get changed items in this cell.

                                var cellitems = tcell.GetText(Constants.FTI_CharPropsChange);

                                for (var i=0; i < cellitems.len ; i +=1) {

                                    // Find out if the Cell has a changebar.

                                    // The result of the bitwise AND (&) must be greater than 0 or no changebar.

                                    var c = cellitems[i].idata & Constants.FTF_CHANGEBAR;

                                    if (c > 0) {

                                        return true;

                                    }

                                }

                                tcell = tcell.NextCellInTbl;

                            }

                        }