Highlighted

iterate all tables in framemaker

Participant ,
Feb 27, 2019

Copy link to clipboard

Copied

Hi,

i want to iterate all tables.. and process table contents

how to do it through script?

pls help

TOPICS
Scripting

Views

1.9K

Likes

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

iterate all tables in framemaker

Participant ,
Feb 27, 2019

Copy link to clipboard

Copied

Hi,

i want to iterate all tables.. and process table contents

how to do it through script?

pls help

TOPICS
Scripting

Views

1.9K

Likes

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
Feb 27, 2019 0
Advocate ,
Feb 27, 2019

Copy link to clipboard

Copied

Even though it is totally unclear what you want to do with the tables, there is a basic approach to visiting all the tables in a document:

var oDoc = app.ActiveDoc;

var oTable = oDoc.FirstTblInDoc;

while( oTable.ObjectValid( ) )

{

     // do something with the oTable object

     oTable = oTable.NextTblInDoc;

}

Note that this linked list also contains the tables on the reference pages, so you will have to check the table tag to see if it is a table you need to process. Nomally the tables on your body pages will use a format tag that is not also used by the tables on the reference pages (this linked list is one of the reasons to stick to that rule of thumb).

To check the format of the table, use oTable.TblTag.

To figure out what to do with the contents of the table, use the FrameMaker Scripting Guide. Look up the Tbl object, see which children it has, look up the properties of those child objects, etc. Make small steps, add lots of alerts in your scripts to see if each step works, then proceed with the next little step. It will become easier when you learn from initial mistakes.

Good luck

Likes

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
Reply
Loading...
Feb 27, 2019 0
Participant ,
Feb 27, 2019

Copy link to clipboard

Copied

Hi,

i have checked table properties and make script upto getting cell.. but i have lacked in getting contents of the cell..

like get paragraph contents, var textList = pgf.GetText (Constants.FTI_CharPropsChange);

doc = app.ActiveDoc;

table = doc.FirstTblInDoc ;

row = table.FirstRowInTbl;

while(table.ObjectValid()){

    while (row.ObjectValid()) { //traverse rows

        cell = row.FirstCellInRow;

        while (cell.ObjectValid()) { //traverse cells in row

         

            cell = cell.NextCellInRow;

        }

        row = row.NextRowInTbl;

    }

     table =table.NextTblInDoc;

}

Likes

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
Reply
Loading...
Feb 27, 2019 0
Adobe Community Professional ,
Feb 27, 2019

Copy link to clipboard

Copied

This is not the best approach. Don't start at the top with tables; start at the bottom with the contents of the cell and what you want to do with it. Cells contain paragraphs. Put your cursor in a paragraph and start with this code:

#target framemaker

var doc, pgf;

doc = app.ActiveDoc;

pgf = doc.TextSelection.beg.obj;

OK, what do you need to do with the paragraph? Are you collected information, changing things, etc.?

Likes

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
Reply
Loading...
Feb 27, 2019 0
Advocate ,
Feb 27, 2019

Copy link to clipboard

Copied

Well, if the script is going to go through all the table contents, it is the right approach.

The step that is missing is the inner loop, going through the paragraphs in each cell:

doc = app.ActiveDoc;

table = doc.FirstTblInDoc ;

row = table.FirstRowInTbl;

while(table.ObjectValid()){

    while (row.ObjectValid()) { //traverse rows

        cell = row.FirstCellInRow;

        while (cell.ObjectValid()) { //traverse cells in row

            pgf = cell.FirstPgf;

            while( pgf.ObjectValid()) {

                    // this is where you can put code to get text, or text properties from the paragraph.

               }

               pgf = pgf.NextPgInFlow;

          }

            cell = cell.NextCellInRow;

        }

        row = row.NextRowInTbl;

    }

     table =table.NextTblInDoc;

}

Likes

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
Reply
Loading...
Feb 27, 2019 0
Enthusiast ,
Feb 27, 2019

Copy link to clipboard

Copied

doc = app.ActiveDoc;

table = doc.FirstTblInDoc ;

while(table.ObjectValid()){

row = table.FirstRowInTbl;

    while (row.ObjectValid()) { //traverse rows

        cell = row.FirstCellInRow;

        while (cell.ObjectValid()) { //traverse cells in row

            pgf = cell.FirstPgf;

            while( pgf.ObjectValid()) {

                    // this is where you can put code to get text, or text properties from the paragraph.

               }

               pgf = pgf.NextPgInFlow;

          }

            cell = cell.NextCellInRow;

        }

        row = row.NextRowInTbl;

    }

     table =table.NextTblInDoc;

}

IMPORTANT!

line 06 MUST be after the first while-loop

Likes

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
Reply
Loading...
Feb 27, 2019 0
Participant ,
Feb 27, 2019

Copy link to clipboard

Copied

Yes.. i want to check the font size of the text in table.. for find and replace the font size.. and check font family of the text in table.

Likes

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
Reply
Loading...
Feb 27, 2019 0
Participant ,
Feb 27, 2019

Copy link to clipboard

Copied

table = doc.FirstTblInDoc;

while(table.ObjectValid()){

    row = table.FirstRowInTbl;

    while (row.ObjectValid()) {     

        cell = row.FirstCellInRow;

        while(cell.ObjectValid()){      

            pgf = cell.FirstPgf;

            while(pgf.ObjectValid()){            

                alert(pgf);

                pgf = pgf.NextPgfInFlow;

                }

            cell = cell.NextCellInRow;

            }

       row = row.NextRowInTbl;

    }

    table = table.NextTblInDoc;

}

the result of the above script is infinite loop.. how to i fix that?

pls help

Likes

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
Reply
Loading...
Feb 27, 2019 0
Advocate ,
Feb 27, 2019

Copy link to clipboard

Copied

No it is not looping infinitely. It is working its way through all the paragraphs in all the cells in ALL the tables, and there are a LOT of tables in the reference pages of your document.

Instead of using alert(pgf) you should use something more informative, such as alert( pgf.Unique ) - which gives you the unique internatl number of the paragraph in the document. That is how you would have seen that it is NOT an infinite loop, just a very long one. In general, putting alerts everywhere is a very slow method. If you do want to prevent an infinite loop, add a counter and make your while loops stop when the counter reaches a high number.

Now about the real problem you are having:

I told you before you need to determine the table format and then decide if you want to iterate through all its cells. The tables on your body pages have a table format that is probably different from the table formats used on the reference pages. You need to check the table format tag of the table you find and then skip the inner loop if it is not one of the formats used on your body pages. Something like this:

while( table.ObjectValid( ) )

{

     if( table.TblTag == "Format A" || table.TblTag == "Format B" )

     {

          /* insert the existing code here for looping through the rows, cells, pgfs.

     }

     table = table.NextTblInDoc;

}

Most of the tables on the reference pages have the table format tag "Mapping Table", so you can also reverse the logic and replace the if statement with this:

if( table.TblTag != "Mapping Table" )

Likes

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
Reply
Loading...
Feb 27, 2019 0
Participant ,
Feb 28, 2019

Copy link to clipboard

Copied

Thank for your response..

I have used following code for get tables

  var oTables = locFlow.GetText(Constants.FTI_TblAnchor);

it returns all tables only in document

at final i have done my task with your guidance and frameexpert​ response

Thank you

Likes

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
Reply
Loading...
Feb 28, 2019 0