Answered
Apply para format to table selection
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 (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();
// 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 (pgf, name, doc);
function applyPgfFmt (pgf, name, doc) {
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. 🙏
I'd really appreciate any help, as I have absolutely no idea how to solve this mess. 🙏
