Skip to main content
Community Expert
January 30, 2025
Answered

ExtendScript - How to remove condition from a table

  • January 30, 2025
  • 1 reply
  • 185 views

Hi,

I have a script which should remove conditions from a table.

This is based on Rick's blog post:

http://frameautomation.com/removing-conditions-from-text-and-table-rows-part-2/

 

To test my attempt, create a document with a table, apply a condition (or several) to the table rows and place the insertion mark in the table.

Here is my script attempt:

#target framemaker
"use strict";
#strict on

var loDoc, loTbl, loTRange, loTblCell;
loDoc = app.ActiveDoc;
loTRange = loDoc.TextSelection;
loPgf = loTRange.beg.obj;
loTblCell = loPgf.InTextObj;
loTbl = loTblCell.CellRow.RowTbl;
RemoveCondFmtFromTbl (loTbl);

function RemoveCondFmtFromTbl (foTbl)
// From Rick Quatro.
// http://frameautomation.com/removing-conditions-from-text-and-table-rows-part-2/
{  
    var loRow, laArrayInCond;
    // Remove all conditions from the list and update the row.
    loRow = foTbl.FirstRowInTbl;
    while (loRow.ObjectValid()) {
        laArrayInCond = loRow.InCond;
        $.writeln ("     laArrayInCond: " + laArrayInCond + "\n" +
            "     laArrayInCond.length: " + laArrayInCond.length);
        laArrayInCond.length = 0;
        loRow.InCond = laArrayInCond;
        loRow = loRow.NextRowInTbl;
    }
} // --- end RemoveCondFmtFromTbl

The values of the laArrayInCond are listed correctly.

However, when I set the array length to 0 and apply the array to a table row, nothing happens.

 

When I remove conditions from the paragraphs with the table anchor, then this works, but I have to press CTRL+L. loDoc.Reformat/RehyphenateloDoc.Redisplay; does not work.

However, CTRL+L does not help here.

Thank you very much for your help!

Best regards, Winfried

    Correct answer Winfried Reng

    Finally I found a solution. There was a script from Klaus Daube, and @Klaus Göbel pointed me to a missing line (setting also isval). Thank you very much!

    This function removes all conditions from all table rows.

    function RemoveCondFmtFromTbl (foTbl)
    // From Klaus Göbel.
    {  
        var loRow, lProps, lPropIndex;
        // Remove all conditions from the list and update the row.
        loRow = foTbl.FirstRowInTbl;
        while (loRow.ObjectValid()) {
            lProps = loRow.GetProps ();
            lPropIndex = GetPropIndex (lProps, Constants.FP_InCond);
            lProps [lPropIndex].propVal.osval.length = 0; 
            lProps [lPropIndex].propVal.isval.length = 0;
            loRow.SetProps (lProps);
            loRow = loRow.NextRowInTbl;
        }
    } // --- end RemoveCondFmtFromTbl

     

    1 reply

    Winfried RengCommunity ExpertAuthorCorrect answer
    Community Expert
    February 3, 2025

    Finally I found a solution. There was a script from Klaus Daube, and @Klaus Göbel pointed me to a missing line (setting also isval). Thank you very much!

    This function removes all conditions from all table rows.

    function RemoveCondFmtFromTbl (foTbl)
    // From Klaus Göbel.
    {  
        var loRow, lProps, lPropIndex;
        // Remove all conditions from the list and update the row.
        loRow = foTbl.FirstRowInTbl;
        while (loRow.ObjectValid()) {
            lProps = loRow.GetProps ();
            lPropIndex = GetPropIndex (lProps, Constants.FP_InCond);
            lProps [lPropIndex].propVal.osval.length = 0; 
            lProps [lPropIndex].propVal.isval.length = 0;
            loRow.SetProps (lProps);
            loRow = loRow.NextRowInTbl;
        }
    } // --- end RemoveCondFmtFromTbl