Copy link to clipboard
Copied
Edit 2022-06-25
Dear experts
I developed a script derived from Rick Quatro's excursus on Deleting Conditions.
→ Running the script does not remove the condition from the text.
Any ideas about this?
For easy testing my case you have here a complete script with no dependencies...
Use the test file on my website.
//@target framemaker
var KLD_Z = KLD_Z || {}; // global script object
KLD_Z.RemoveConditionsFromText = function (oDoc, oTR, aRemoveConds) { // ======
/* Get the list of properties and methods (functions) of an object
Arguments oDoc Current document
oTR TextRange of the found conditions
aRemoveConds Array of conditions (names) to be removed
Reference http://frameautomation.com/removing-conditions-from-text-and-table-rows-part-4/
*/
var oProps, asCondFmts, j;
oProps = oDoc.GetTextPropVal (oTR.beg, Constants.FP_InCond);
asCondFmts = oProps.propVal.osval; // Get a list of the conditions
if (asCondFmts.length === 0) {
return; // No conditions are applied to the text range
}
for (j = 0; j < asCondFmts.length; j += 1) {
if (KLD_Z.IsInArray (aRemoveConds, asCondFmts[j].Name) != null) {
Array.prototype.splice.call (asCondFmts, j, 1); // Remove from list.
}
}
// Following condition is always false
if (asCondFmts.length !== oProps.propVal.osval.length) {
oProps.propVal.osval = asCondFmts; // apply updated list back to TR
oDoc.SetTextPropVal (oTR, oProps);
}
} // End RemoveConditionsFromText ---------------------------------------
KLD_Z.IsInArray = function (array, item) { //==========================
/* Get index of item in array
Returns Index of found item or null
*/
var j, jMax;
jMax = array.length;
for (j = 0; j < jMax; j++) {
if (array [j] == item ) { return j;}
}
return null; // not found in array
} //--- end IsInArray -------------------------------------------------
KLD_Z.GetFindParameters = function (sFType, sSearch) { //==============
// stripped down to the essentials for this test case
var findParms, jj, oPropVal1, oPropVal2;
findParms = new PropVals();
oPropVal1 = new PropVal() ; // ---------------- NoWrap
oPropVal1.propIdent.num = Constants.FS_FindWrap ;
oPropVal1.propVal.valType = Constants.FT_Integer;
oPropVal1.propVal.ival = 0 ; // no wrap
findParms.push(oPropVal1);
oPropVal2 = new PropVal() ;
if (sFType == "CONTAG") { // ------------------- Conditional tags
oPropVal2.propIdent.num = Constants.FS_FindCondTextInCondTags;
oPropVal2.propVal.valType = Constants.FT_Strings;
oPropVal2.propVal.ssval[0] = sSearch; // "cond1"
// The following does not work in ES
// for (jj = 0; jj < sSearch.length; jj++) { // ["cond1", "cond2", …]
// oPropVal2.propVal.ssval[jj] = sSearch[jj];
// }
}
findParms.push(oPropVal2);
return findParms;
} //--- end GetFindParameters ----------------------------------------
KLD_Z.main = function () { // <><><><><><><><><><><><><><><><><><><><><
var oDoc, oFindParms, oTR;
oDoc=app.ActiveDoc;
oTR = oDoc.TextSelection
// Create a text Selection of the conditional text
$.bp(true);
oFindParms = KLD_Z.GetFindParameters ("CONTAG", "Comment");
oTR = oDoc.Find(oTR.beg, oFindParms);
oDoc.TextSelection = oTR;
KLD_Z.RemoveConditionsFromText (oDoc,oTR, ["Comment"]);
} //--- end main ------------------------------------------------------
KLD_Z.main ();
Copy link to clipboard
Copied
Observation two:
When eliminating the final if in function RemoveConditionsFromText
// Following condition is always false
//if (asCondFmts.length !== oProps.propVal.osval.length) {
oProps.propVal.osval = asCondFmts; // apply updated list back to TR
oDoc.SetTextPropVal (oTR, oProps);
//}
... then in the TR with the combined conditions ...
... the non-overlapping condition Comment is removed, and the combination (Comment+Detail) is extended into this area.
Copy link to clipboard
Copied
IMHO the second statement in the sequence does not what it should.
//if (asCondFmts.length !== oProps.propVal.osval.length) {
oProps.propVal.osval = asCondFmts; // apply the updated OK
oDoc.SetTextPropVal (oTR, oProps);
//}
oPropsDone = oDoc.GetTextPropVal (oTR.beg, Constants.FP_InCond); // NOK
Therefore I added the test oPropsDone.
At line "OK" | At line "NOK" |
Do You have any ideas what's going on here?