Skip to main content
alexanderp3125138
Inspiring
February 11, 2020
Answered

Apply para format to table selection

  • February 11, 2020
  • 1 reply
  • 713 views
Alright folks, please bear with me... 🙊
I'm completely new to both FrameMaker and scripting. What I'm trying to achieve is the following:
 
1. Convert first row of a table to a heading row
2. Apply a specific paragraph style to all contents of the table
 
By shameless use of copy & paste, I managed to achieve goal #1 so far. In addition, I managed to select the whole table, but then I hit a roadblock.
The code snippet I'm using to apply a para style does work when I place the cursor somewhere in the text, but it doesn't do anything when the table is selected.
 
This is what I've got so far:

#
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, then select whole table
bodyToHeadingRow (tbl1doc);

function bodyToHeadingRow (tblnumdoc) {

    var row = 0;

    // Select the top "num" rows in the table.
    tbl.MakeTblSelection (0num - 10tbl.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_Headingnum);

    // Select the new heading rows.
    tbl.MakeTblSelection (0num - 10tbl.TblNumCols - 1);

    // Paste the rows from the clipboard into the new heading rows.
    doc.Paste (Constants.FF_REPLACE_CELLS);

    // Restore the clipboard contents.
    PopClipboard();

    // Select whole table.
    tbl.MakeTblSelection (Constants.FF_SELECT_WHOLE_TABLE);
     
}

var pgf = doc.TextSelection.beg.obj;
var name = "TableFont";

//Convert para style in table
applyPgfFmt (pgfnamedoc);

function applyPgfFmt (pgfnamedoc) {

    var pgfFmt = 0;

    pgfFmt = doc.GetNamedPgfFmt (name);

    if (pgfFmt.ObjectValid ()) {
        var props = pgfFmt.GetProps ();
        pgf.SetProps(props);
    }
    else {
        pgf.Name = name;
     }
}

I'd really appreciate any help, as I have absolutely no idea how to solve this mess. 🙏
This topic has been closed for replies.
Correct answer frameexpert

I assume you mean that you want to apply a paragraph format to each paragraph in each cell of the table. You have to loop through all of the cells in the table and then loop through all of the paragraphs in each cell. Selecting the table is not necessary.

cell = tbl.FirstRowInTbl.FirstCellInRow;
while (cell.ObjectValid () === 1) {
    if (cell.CellIsStraddled === 0) {
        pgf = cell.FirstPgf;
        while (pgf.ObjectValid () === 1) {
            applyPgfFmt (pgf, name, doc);
            pgf = pgf.NextPgfInFlow;
        }
    }
    cell = cell.NextCellInTbl;
}

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
February 11, 2020

I assume you mean that you want to apply a paragraph format to each paragraph in each cell of the table. You have to loop through all of the cells in the table and then loop through all of the paragraphs in each cell. Selecting the table is not necessary.

cell = tbl.FirstRowInTbl.FirstCellInRow;
while (cell.ObjectValid () === 1) {
    if (cell.CellIsStraddled === 0) {
        pgf = cell.FirstPgf;
        while (pgf.ObjectValid () === 1) {
            applyPgfFmt (pgf, name, doc);
            pgf = pgf.NextPgfInFlow;
        }
    }
    cell = cell.NextCellInTbl;
}
www.frameexpert.com
alexanderp3125138
Inspiring
February 11, 2020

Hooray, it's working!!´🎉

Cycling through the table cells makes perfect sense to me now you mention it. Thanks a lot for the quick reply!