5 Replies Latest reply on Oct 15, 2015 6:09 AM by frameexpert

    finding cell overflow in table - problem with script

    vereeckG

      Hello,

       

      as a translation company, we often do some DTP on translated Framemaker documents. The documents often contain many tables, and the translated text doesn't always fit into the cells, giving overflow. I'm looking into creating a script that finds the overflow in the table cells.

       

      I've already tested some scripts, and have now run into an issue I can't seem to work out. I started out by detecting the overflowed cells in a selected table, which works fine, and gives an alerts when overflow is detected. This script:

      // == WORKS ON SELECTED TABLE ==
      var doc = app.ActiveDoc;  
      var tbl = doc.SelectedTbl;  
      var row = tbl.FirstRowInTbl;  
      var cell;  
        
      while (row.ObjectValid () === 1) {  
          cell = row.FirstCellInRow;  
          while (cell.ObjectValid () === 1)  {  
           if (cell.Overflowed === 1) {  
        alert("cell overflow Will Robinson!");
        }
              cell = cell.NextCellInRow;  
          }  
          row = row.NextRowInTbl;  
      }  
      // == END OF WORKS ON SELECTED TABLE ==
      

       

      However, I thought it would be nice to loop through the tables in a document, and find all overflowed cells, instead of going table by table. So this script successfully loops through tables, rows and cells in a document:

      // === LOOPS THROUGH TABLE, NO OVERFLOW ===
      var doc = app.ActiveDoc;
      var tbl = app.ActiveDoc.FirstTblInDoc;
      var row = tbl.FirstRowInTbl;
      var cell;
      
      
      while (tbl.ObjectValid()) {
        alert ("gimme a table");
        while (row.ObjectValid () === 1) {
        cell = row.FirstCellInRow;  
        while (cell.ObjectValid () === 1)  {  
        alert("gimme a cell");
        cell = cell.NextCellInRow;
        }
        row = row.NextRowInTbl;
        }
      tbl = tbl.NextTblInDoc;  
      }    
      // === END OF LOOPS THROUGH TABLE, NO OVERFLOW ===
      

       

      When I add the block

          while (cell.ObjectValid () === 1)  {  
           if (cell.Overflowed === 1) {  
        alert("cell overflow Will Robinson!");
      

      into this script, it doesn't work. It appears the cell.OverFlowed needs the table to be selected? Does anyone know how to get around this -by either selecting the table if the object is valid before looping through the rows, or by detecting the cell.OverFlowed in the above script?

       

      I also -because why not:) - tried running the overflowed on the doc.flow instead of FirstTbl, but although it detects flowes/frames and subcol correctly, it still doesn't register the overflow.

      var doc = app.ActiveDoc
      var flow = doc.FirstFlowInDoc
      var frame = flow.FirstTextFrameInFlow
      var subcol =frame.FirstSubCol
      
      while (flow.ObjectValid()){        
                  while (frame.ObjectValid()) {               
                          while (subcol.ObjectValid()){
                              if (subcol.OverFlowed === 1){
                              alert("colsies"); //doesn't work!
                              }
                              subcol = subcol.NextSubCol
                              }
                      frame = frame.NextTextFrameInFlow
                      }
                  flow = flow.NextFlowInDoc
         }
      

       

      I'm clearly missing something, but I can't seem to figure out what? Any help would be greatly appreciated...

       

      Kind regards,

      Geert