Skip to main content
roottechie
Participating Frequently
May 6, 2014
Answered

How do I change the table's first row to a Heading row if it contains pgfs with tblHead tags

  • May 6, 2014
  • 2 replies
  • 1400 views

So far, I have the following in a JavaScript:

if (tbl.FirstRowInTbl.FirstCellInRow.FirstPgf.PgfFmt.Name === "tblHead")

        {

            if (tbl.FirstRowInTbl.RowType === 1)

                //1 is Constants.FV_ROW_BODY

                tbl.FirstRowInTbl.RowType = 0;

                // 0 is Constants.FV_ROW_HEADING

            else

                continue;

         }

        else

            continue;

This does not work. I'm not comfortable with tbl.FirstRowInTbl.FirstCellInRow.FirstPgf.PgfFmt.Name.

It is clearly wrong. How would I indicate I want to determine the tag of the first paragraph in the first row?

Any help is very much appreciated!

Thanks,

Ruth

This topic has been closed for replies.
Correct answer frameexpert

Russ:

Thank you for this information. I’ll see if I can take those actions you recommend… that’s exactly what I will have to do by hand if I can’t get the script to do it! ☺

Ruth


Ruth, here is a function that will convert body rows to heading rows in a table. Please let me know if you have any questions or comments. -Rick

#target framemaker

var doc = app.ActiveDoc;

// Set a variable for the selected table.

var tbl = doc.SelectedTbl;

// Convert the first body row to a heading row.

bodyToHeadingRow (tbl, 1, doc);

function bodyToHeadingRow (tbl, num, doc) {

   

    var row = 0;

   

    // Select the top "num" rows in the table.

    tbl.MakeTblSelection (0, num - 1, 0, tbl.TblNumCols - 1);

    // Push the current clipboard contents and cut the selected rows.

    PushClipboard ();

    doc.Cut (Constants.FF_CUT_TBL_CELLS);

    // Add "num" number of heading rows to the table.

    row = tbl.FirstRowInTbl;

    row.AddRows (Constants.FV_Heading, num);

    // Select the new heading rows.

    tbl.MakeTblSelection (0, num - 1, 0, tbl.TblNumCols - 1);

    // Paste the rows from the clipboard into the new heading rows.

    doc.Paste (Constants.FF_REPLACE_CELLS);

    // Restore the clipboard contents.

    PopClipboard();

   

}

2 replies

frameexpert
Community Expert
Community Expert
May 7, 2014

Hi Ruth,

This:

if (tbl.FirstRowInTbl.FirstCellInRow.FirstPgf.PgfFmt.Name === "tblHead")


should be


if (tbl.FirstRowInTbl.FirstCellInRow.FirstPgf.Name === "tblHead")


I agree with Jang; sometimes having long property strings can be hard to follow and debug. You should at least capture the row in a variable since you have to work with it later in the script.


var row = tbl.FirstRowInTbl;

var cell = row.FirstCellInRow;

if (cell.FirstPgf.Name === "tblHead")

...


Russ is right, you can't just change the RowType because it is read only. If I have time later I will post the code that shows how to do this.


Rick

www.frameexpert.com
4everJang
Legend
May 7, 2014

Ruth,

You will have to develop this step by step. You might assume that something is 'clearly' wrong, but you only know when you let the script tell you what it found. So either use the debugger and look at the values in the data browser, or insert an alert to see what the actual value is that the script found. Then proceed, small step by small step.

In general, I am not a big fan of those long strings of properties like the one you use in your if statement. Try breaking it up in smaller pieces, use variables to hold the values and objects, and either alert ( varname ) or Console ( varname ) to see what their values are at given points in the script.

Good luck

Jang

Legend
May 7, 2014

Hi Ruth,

One big problem with your script is that the RowType property is read-only. So, you can't just change a row type by setting a new value. You have to insert a new heading row, copy the data over from the body row, then delete the body row. This is a lot more complicated obviously, but it follows the FrameMaker table model and it is consistent with row management within the GUI.

The line of code that you claim is "clearly wrong" doesn't look wrong to me, at a glance. If you aren't sure if it is locating what you want, put some extra code in there to test, like an alert() or confirm() box with each match to see what it is actually doing. Jang suggests the debugger as well, although be warned that the ES toolkit debug environment is not for the faint of heart.

Russ

roottechie
Participating Frequently
May 7, 2014

Russ:

Thank you for this information. I’ll see if I can take those actions you recommend… that’s exactly what I will have to do by hand if I can’t get the script to do it! ☺

Ruth