Copy link to clipboard
Copied
Dear all,
In a previous project the setting of such a flag was successful:
oPropVal = new PropVal() ;
oPropVal.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal.propVal.valType = Constants.FT_Integer;
oPropVal.propVal.ival = Constants.FF_FIND_BACKWARDS ;
findParams.push(oPropVal);
But now, in a more general set-up the flags are not set:
if (bWord || bCase || bBack || bRegEx || bWild) {
oPropVal3 = new PropVal() ;
oPropVal3.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal3.propVal.valType = Constants.FT_Integer;
oPropVal3.propVal.ival = 0;
if (bCase) {oPropVal3.propVal.ival || Constants.FF_FIND_CONSIDER_CASE;}
if (bRegEx) {oPropVal3.propVal.ival || Constants.FF_FIND_USE_REGEX;
} else {
if (bWild) {oPropVal3.propVal.ival || Constants.FF_FIND_USE_WILDCARDS;}
if (bWord) {oPropVal3.propVal.ival || Constants.FF_FIND_WHOLE_WORD;}
if (bBack) {oPropVal3.propVal.ival || Constants.FF_FIND_BACKWARDS;}
}
findParms.push(oPropVal3);
}
A break point prior to FindParms.push (oPropVal3) and inspection of the object tells me that ival is not sufficiently defined:
What is wrong with my definitions?
Wait a minute
Just now here in the browser the view on the subject is different: there are no = assignments...
1 Correct answer
Sorry folks, the whole issue is a Hornberger Schiessen (wild goose chase):
The error messages in the Data Browser are irrelevant for the positive result. The script successfully finds 1st, 2nd, 4th and 5th and refuses to find 3Rd - hence RegEx search is OK and Consider Case is observed:
/*Test_MiniFind.jsx ====== UTF-8 ==========================================
Test for the functions GetFindParameters, FindSomething
History 2020-12-09
*/ ; // ==================================
...
Copy link to clipboard
Copied
Huch, can not delete this
Copy link to clipboard
Copied
It must look like this
if (bWord || bCase || bBack || bRegEx || bWild) { // customisation flags are ORED
oPropVal3 = new PropVal() ;
oPropVal3.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal3.propVal.valType = Constants.FT_Integer;
ival3 = 0;
if (bCase) { ival3 = ival3 || Constants.FF_FIND_CONSIDER_CASE;} // 0x01
if (bRegEx) { ival3 = ival3 || Constants.FF_FIND_USE_REGEX; // 0x10
} else {
if (bWild) { ival3 = ival3 || Constants.FF_FIND_USE_WILDCARDS;} // 0x04
if (bWord) { ival3 = ival3 || Constants.FF_FIND_WHOLE_WORD;} // 0x02
if (bBack) { ival3 = ival3 || Constants.FF_FIND_BACKWARDS;} // 0x08
}
oPropVal3.propVal.ival = ival3;
findParms.push(oPropVal3);
}
But this does not help!
I still have this «ssval does not have a value»
Copy link to clipboard
Copied
Hi Klaus,
When you OR flags together, you use a single pipe | character. For example, here is a function where I am getting Import Formats settings:
GS_ANT.getImportFormatsFlags = function (settings) {
var flags = 0;
// Paragraph formats.
flags = flags | Constants.FF_UFF_PGF;
// Character formats.
flags = flags | Constants.FF_UFF_FONT;
// Table formats.
flags = flags | Constants.FF_UFF_TABLE;
// Page layouts.
flags = flags | Constants.FF_UFF_PAGE;
// Reference pages.
flags = flags | Constants.FF_UFF_REFPAGE;
// Colors.
flags = flags | Constants.FF_UFF_COLOR;
// Combined fonts.
flags = flags | Constants.FF_UFF_COMBINED_FONTS;
// Conditional text settings.
flags = flags | Constants.FF_UFF_COND;
// Math settings.
flags = flags | Constants.FF_UFF_MATH;
// Cross-reference formats.
flags = flags | Constants.FF_UFF_XREF;
// Filter by attributes settings.
flags = flags | Constants.FF_UFF_FBA;
// Object styles.
flags = flags | 0x2000;
// Page breaks.
flags = flags | Constants.FF_UFF_REMOVE_PAGE_BREAKS;
// Format overrides.
flags = flags | Constants.FF_UFF_REMOVE_EXCEPTIONS;
return flags;
};
Copy link to clipboard
Copied
Thank you very much, Rick!
It is not obious for me why for a relation I need || or && and for logical OR/AND only one symbol... Well, syntax details are a problem for me since the old Fortran days...
While flags are now correctly 'accumulated' the resulting propval still is not correct:
flags = 0;
if (bCase) { flags = flags | Constants.FF_FIND_CONSIDER_CASE;} // 0x01
if (bRegEx) { flags = flags | Constants.FF_FIND_USE_REGEX; // 0x10
propVal4 = new PropVal ();
propVal4.propIdent.num = Constants.FS_RegexFlavour;
propVal4.propVal.valType = Constants.FT_Integer;
propVal4.propVal.ival = Constants.FR_USE_PERL;
findParms.push(propVal4);
} else {
if (bWild) { flags = flags | Constants.FF_FIND_USE_WILDCARDS;} // 0x04
if (bWord) { flags = flags | Constants.FF_FIND_WHOLE_WORD;} // 0x02
if (bBack) { flags = flags | Constants.FF_FIND_BACKWARDS;} // 0x08
}
oPropVal3.propVal.ival = flags;
Copy link to clipboard
Copied
This is absolutely ridiculous.
I have checked with numerous examples, e.g. this one by Ian Proudfoot on https://community.adobe.com/t5/framemaker/find-replace/td-p/3581679
findParams = AllocatePropVals(2);
findParams[0].propIdent.num = Constants.FS_FindText;
findParams[0].propVal.valType = Constants.FT_String;
findParams[0].propVal.sval = findString;
findParams[1].propIdent.num = Constants.FS_FindCustomizationFlags;
findParams[1].propVal.valType = Constants.FT_Integer;
if(considerCase){
findParams[1].propVal.ival = Constants.FF_FIND_CONSIDER_CASE;
}
else{
findParams[1].propVal.ival = 0;
}
I can not recognise any logical difference to my statements:
oPropVal3 = new PropVal() ;
oPropVal3.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal3.propVal.valType = Constants.FT_Integer;
qFlags = 0;
...
if (bWord) { qFlags = qFlags | Constants.FF_FIND_WHOLE_WORD;} // 0x02
...
oPropVal3.propVal.ival = qFlags;
But ES insists on the error
Is there a hidden character in my statement? Is the casing not correct? What is going on here?
BTW: again the ES documentation is very weak for this problem. Even the FDK documentation is not that clear about the structure of the propvals.
Copy link to clipboard
Copied
I have now shrinked the script to the (what I think) bare minimum:
/* Test_GetFindParameters.jsx ====== UTF-8 ================================
Test for the functions GetFindParameters, FindSomething
History 2020-12-05 test with VSCode and ESDebugger
*/ ; // ==================================================================
//@target framemaker
var KLD_Z = KLD_Z || {}; // global script object
KLD_Z.GetFindParameters = function (sSearch) { //====
// Set up a text find with case sensitive RegEx
var bRegEx, findParms, qFlags, oPropVal1, oPropVal2, oPropVal3;
findParms = new PropVals();
oPropVal1 = new PropVal() ;
oPropVal1.propIdent.num = Constants.FS_FindText;
oPropVal1.propVal.valType = Constants.FT_String;
oPropVal1.propVal.sval = sSearch;
findParms.push(oPropVal1);
oPropVal2 = new PropVal() ;
oPropVal2.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal2.propVal.valType = Constants.FT_Integer;
qFlags = 0;
qFlags = qFlags | Constants.FF_FIND_CONSIDER_CASE; // 0x01
qFlags = qFlags | Constants.FF_FIND_USE_REGEX; // 0x10
oPropVal2.propVal.ival = qFlags; //
findParms.push(oPropVal2);
oPropVal3 = new PropVal ();
oPropVal3.propIdent.num = Constants.FS_RegexFlavour;
oPropVal3.propVal.valType = Constants.FT_Integer;
oPropVal3.propVal.ival = Constants.FR_USE_PERL; // 1
findParms.push(oPropVal3);
$.bp(true); // check oPropVal2 and oPropVal3
return findParms;
} //--- end GetFindParameters -------------------------------------------
KLD_Z.FindSomething = function (oDoc, iFS, iFV, sSearch, iMode, bWord, bCase, bBack, bStart) { // ========
// Find anything defined by the parameters
var oFindParms, oTR, oTRsaved ;
oTRsaved = oDoc.TextSelection; // we may need to come back to the start location
oTR = oDoc.TextSelection; // start from current location
oFindParms = KLD_Z.GetFindParameters (sSearch); // set up for text search, case sentive RegEx
oTR = oDoc.Find(oTR.beg, oFindParms);
if (FA_errno === Constants.FE_Success) { // 0: FE_Success; -95: FE_NotFound
return oTR;
} else { // Not found
return undefined;
}
} //--- end FindSomething -----------------------------------------------
KLD_Z.main = function () { // ============================================
// Find text containing 1stxxx 2ndxxx 3rdxxx or 4thxxx 5thxxx ...
var oDoc, OK, oTR;
//$.bp(true);
oDoc = app.ActiveDoc;
//OK = KLD_Z.FindSomething (oDoc, iFS, iFV, sSearch, iMode, bWord, bCase, bBack);
//$.bp(true);
oTR = KLD_Z.FindSomething (oDoc, 1, null, "\\d[st|nd|rd|th]", 2, false, false, false);
if (oTR == undefined) {
Alert ("not found");
}
} //--- end main ---------------------------------------------------------
KLD_Z.main ();
But I still get the same errors when lookink at the properties on the line " $.bp(true); // check oPropVal2 and oPropVal3".
Copy link to clipboard
Copied
Sorry folks, the whole issue is a Hornberger Schiessen (wild goose chase):
The error messages in the Data Browser are irrelevant for the positive result. The script successfully finds 1st, 2nd, 4th and 5th and refuses to find 3Rd - hence RegEx search is OK and Consider Case is observed:
/*Test_MiniFind.jsx ====== UTF-8 ==========================================
Test for the functions GetFindParameters, FindSomething
History 2020-12-09
*/ ; // ===================================================================
//#target framemaker
//@target framemaker
function GetFindParameters (sSearch) { //======================
// Set up a text find with case sensitive RegEx
var findParms, qFlags, oPropVal1, oPropVal2, oPropVal3;
findParms = new PropVals();
oPropVal1 = new PropVal() ;
oPropVal1.propIdent.num = Constants.FS_FindText;
oPropVal1.propVal.valType = Constants.FT_String;
oPropVal1.propVal.sval = sSearch;
findParms.push(oPropVal1);
oPropVal2 = new PropVal() ;
oPropVal2.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal2.propVal.valType = Constants.FT_Integer;
qFlags = 0;
qFlags = qFlags | Constants.FF_FIND_CONSIDER_CASE; // 0x01
qFlags = qFlags | Constants.FF_FIND_USE_REGEX; // 0x10
oPropVal2.propVal.ival = qFlags; //
findParms.push(oPropVal2);
oPropVal3 = new PropVal ();
oPropVal3.propIdent.num = Constants.FS_RegexFlavour;
oPropVal3.propVal.valType = Constants.FT_Integer;
oPropVal3.propVal.ival = Constants.FR_USE_PERL; // 1
findParms.push(oPropVal3);
//$.bp(true); // check oPropVal2 and oPropVal3 - ival reports errors...
return findParms;
} //--- end GetFindParameters -------------------------------------------------
function FindSomething (oDoc, sSearch) { // ===============================
var oFindParms, oTR, oTRsaved ;
oTRsaved = oDoc.TextSelection; // we may need to come back
oTR = oDoc.TextSelection; // start from current location
oFindParms = GetFindParameters (sSearch);
if (oFindParms === null) {return undefined;} // oTR has not changed yet
oTR = oDoc.Find(oTR.beg, oFindParms);
if (FA_errno === Constants.FE_Success) { // 0: FE_Success; -95: FE_NotFound
oDoc.TextSelection = oTR; // selection visible ?
oDoc.ScrollToText(oTR); // selection visible ? Yes
return oTR;
} else { // Not found
oDoc.TextSelection = oTRsaved;
oDoc.ScrollToText(oTRsaved);
return undefined;
}
} //--- end FindSomething ------------------------------------------------
function main () { // =====================================================
// testfile: E:\_DDDprojects\_JSX-library\TestFiles\Gugus-file1.fm
// ontains 1st, 2nd, 3Rd, 4th, 5th
var oDoc = app.ActiveDoc, OK, oTR;
oTR = FindSomething (oDoc, "\\d[st|nd|rd|th]"); // text by regex
if (oTR == undefined) {
Alert ("not found");
}
} //--- end main ----------------------------------------------------------
main ();
I do not know yet why my initial script did not work - have to take a very close look to the differences to this working script.

