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

Table cell overflow - script not working

Explorer ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

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

[Thread moved from General forum by moderator - please do not double post]

TOPICS
Scripting

Views

859

Translate

Translate

Report

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 ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

LATEST

Hi Geert,

I can't see anything immediately wrong with your script, so I don't know why it fails when you add the Overflowed check. You should not need to have the table selected.  So, let me ask some general questions, perhaps to inspire some thinking towards a solution:

- In your "alert("cell overflow Will Robinson!");" snippet, you do not show the additional closing brace that would be required. But, I assume you would have known right away if that was omitted.


- When you enhanced the script to iterate over all tables, how do you know that you actually iterated over all tables? Did you actually click through every single cell in the document? There are many tables on the reference pages that your script may pick up before it gets to the body pages. Did you click through a bunch of "gimme a cell" messages and then decide the "cell overflow Will Robinson!" message wasn't working, but actually you had not gotten to the offending table yet?


- You use the "===" operator for comparison. In JavaScript, this means that the comparison should only evaluate to true if the items are the same value AND the same object type. If it worked once, maybe that's OK, but personally I would us just "==" in this case. I'm not sure what is going on under the covers so a simple value comparison seems sufficient.


Here are a few additional troubleshooting suggestions:


- When troubleshooting with alert boxes, I always use confirm() instead, so I can abort the process at any point, For example:


if(!confirm("gimme a cell")) return;


- It is often more informative to report a property of an object, rather than just a static message. For example, if you want to verify that you have a table on a body page, you could do:


alert("gimme a table. Table format: " + tbl.TblTag);



- Although cumbersome to use, you could run this script through the ES toolkit debugger. The debugger would show you all properties of all active objects, so you could evaluate the Overflowed property of a cell object to see what the interface actually sees.


I hope this helps some.


Russ

Votes

Translate

Translate

Report

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