Copy link to clipboard
Copied
Hi all,
I'm using FM 11 on Windows 7.
I'm having trouble deciphering the scripting guide (http://help.adobe.com/en_US/framemaker/scripting/framemaker_10_scripting.pdf) in relation to the SetProps() function. Specifically, I haven't been able to find a good description of the TypedVal properties (p. 400). Does anyone know of a document that describes these properties and how to use them?
My current task is to apply a conditional format to a row, but I would also like to apply a condfmt to an entire table. Here is my most recent (unsuccessful) attempt:
function setRowConditional(row, condFmt)
{
var props = row.GetProps();
var prop = new PropVal();
prop.propIdent.num = Constants.FP_InCond;
prop.propVal.ival = condFmt.id;
prop.propVal.obj = condFmt;
props.push(prop);
row.SetProps(props);
}
Thanks,
Trevor
Blast that Ctrl+S shortcut that sends the message, for FM users that are used to doing Ctrl+S in their sleep.
Anyway, as I was saying, here is a sample I got to work. The doc and row arguments must be valid document and row objects, and condition is the name of the condition to apply. Regarding osval again, I'm thinking that maybe this function is only reliable if the row currently has no other conditions applied.
I thought maybe just to build an array that includes the condFmt and apply it to row
...Copy link to clipboard
Copied
Hi Trevor,
Here is a version that I got to work. I'm not entirely confident that it is the best method, because it seems a little sketchy on how the osval array is managed. However, it does generally follow some other examples I have seen.
Copy link to clipboard
Copied
Blast that Ctrl+S shortcut that sends the message, for FM users that are used to doing Ctrl+S in their sleep.
Anyway, as I was saying, here is a sample I got to work. The doc and row arguments must be valid document and row objects, and condition is the name of the condition to apply. Regarding osval again, I'm thinking that maybe this function is only reliable if the row currently has no other conditions applied.
I thought maybe just to build an array that includes the condFmt and apply it to row.InCond directly, but it kept freezing up FM. I don't know what I was doing wrong.
function applyConditionToRow(doc, row, condition)
{
var condFmt = doc.GetNamedCondFmt(condition);
if(!condFmt.ObjectValid()) return;
var props = row.GetProps();
var propIndex = GetPropIndex(props, Constants.FP_InCond);
props[propIndex].propVal.osval[0] = condFmt;
row.SetProps(props);
}
Copy link to clipboard
Copied
Thanks Russ! Your solution seems to work well for my use case.
Do you have ideas or examples you could point me to for applying a condition to an entire table? Using GetPropIndex(tbl.GetProps(), Constants.FP_InCond); seems to return -4.
Copy link to clipboard
Copied
Trevor,
To do an entire table, you would need to conditionalize the anchor. The table object itself does not have an FP_InCond property like a row.
Because the anchor is part of the text flow, conditionalizing it is like conditionalizing any piece of text. Having said that, it is tricky to figure out.
Here is thread that discusses the application of a condition to a range of text, in this case a whole paragraph:
https://forums.adobe.com/thread/918670
To adapt this to a table anchor, you would need to have the script "select" an anchor rather than a whole paragraph. You would have to first get the TextLoc property of the table and use it to generate the TextRange required for the anchor. The beginning of the text range would be the original TextLoc and the end would be the same location with the offset incremented by one.
Here is a sample that works for me. Again, I'm not 100% confident that this is the best way to do it. I still get a bit confused about array management within PropVal structures.
function applyConditionToTable(doc, table, condition)
{
//Get the format object
var condFmt = doc.GetNamedCondFmt(condition);
if(!condFmt.ObjectValid()) return;
//Get the text location of the table anchor
var textLoc = table.TextLoc;
//Set up a text range to span the anchor, a single character.
var textRange = new TextRange();
textRange.beg.obj = textRange.end.obj = textLoc.obj;
textRange.beg.offset = textLoc.offset ;
textRange.end.offset = textLoc.offset + 1;
//This will select the anchor. Not required... but handy
//for testing.
//doc.TextSelection = textRange;
//Populate a PropVal array for condition formats
//by asking for the current value at the beginning of the anchor.
var props = doc.GetTextPropVal(textRange.beg,Constants.FP_InCond);
//Reset the PropVal to the condition we want.
props.propVal.osval[0] = condFmt;
//Set the revised properties to the full text range.
doc.SetTextPropVal(textRange, props);
}
Russ