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

Apply para format to table selection

Explorer ,
Feb 11, 2020 Feb 11, 2020

Copy link to clipboard

Copied

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. 🙏
TOPICS
Formatting and numbering , Scripting

Views

561

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

correct answers 1 Correct answer

Community Expert , Feb 11, 2020 Feb 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 
...

Votes

Translate

Translate
Community Expert ,
Feb 11, 2020 Feb 11, 2020

Copy link to clipboard

Copied

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;
}

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
Explorer ,
Feb 11, 2020 Feb 11, 2020

Copy link to clipboard

Copied

LATEST

Hooray, it's working!!´:party_popper:

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

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