Using the Find method to get the relevant markers works fine. I did however not succeed in using the linked list. This fails after the first iteration (see Markers can be found, but are undefined
// FollowXRef.jsx
#target framemaker
main ();
function main () {
var oDoc, oPgf, oPgfNew, oTRfound, oTextItem, oTL, oTR, oXRef, oXRefTI, sPath;
oDoc = app.ActiveDoc;
oTL = oDoc.TextSelection.beg;
sXRefFmnt = "zenref-endnote-reference"; // goFno.FmtEnRefName
oFindParams= GetFindParameters (8, sXRefFmnt); // find XRef forwards
oTRfound = oDoc.Find(oTL, oFindParams);
if (oTRfound.beg.obj.ObjectValid()) {
oXRefTI = oDoc.GetTextForRange (oTRfound, Constants.FTI_XRefBegin); // one 1 item in array
for (k = 0; k < oXRefTI.length; k++) { // k always 0 nevertheless loop necessary!
oXRef = oXRefTI.obj;
}
}
// ------------------------------------------------------------------------------------------------
oTR = FollowXRef (oDoc, oXRef); // oXRef.XRefFile can be relative "\endnote".
// ------------------------------------------------------------------------------------------------
sPath = oXRef.XRefFile; // Some experiment to verify the TextRange
if (sPath == "") { // XRef marker in same file
oTgtDoc = oDoc;
} else {
oTgtDoc = SimpleOpen (oXRef.XRefFile) ; // File with XRef (may be relative "\endotes"
}
app.ActiveDoc = oTgtDoc; // Ttarget doc with XRef marker
oPgf = oTR.beg.obj.PrevPgfInFlow;
oPgfNew = oTgtDoc.NewSeriesPgf(oPgf); // new empty ¶ after previous ¶
} //--- end main
function FollowXRef (oDoc, oXRef) { // === jump to the target of the cross reference ==============
// Arguments oDoc Current document
// oXRef Cross reference to follow, target may be another document!
// Returns false in case of problems
// Called by xx
var docStart, k, oFindParams, oMarker, oMarkTI, oTgtDoc, oTL, oTRfound, oTR, sDocPath, sMarkerText, sPath;
app.ActiveDoc = oDoc; // required ?
sDocPath = oDoc.Name;
sPath = oXRef.XRefFile;
if (sPath == "") { // XRef marker in same file
oTgtDoc = oDoc;
} else {
oTgtDoc = SimpleOpen (oXRef.XRefFile) ; // File with XRef (may be relative "\endotes"
}
sMarkerText = oXRef.XRefSrcText
app.ActiveDoc = oTgtDoc; // Target doc with XRef marker
docStart = oTgtDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
oTL = new TextLoc (docStart, 0);
oFindParams= GetFindParameters (3, "Cross-Ref"); // find XRef marker
oTRfound = oTgtDoc.Find(oTL, oFindParams);
while (oTRfound.beg.obj.ObjectValid()) {
oMarkTI = oTgtDoc.GetTextForRange (oTRfound, Constants.FTI_MarkerAnchor); // one 1 item in array
for (k = 0; k < oMarkTI.length; k++) { // k always 0 nevertheless loop required!
oMarker = oMarkTI.obj;
if (oMarker.MarkerText == sMarkerText) {
oTR = new TextRange (oMarker.TextLoc, oMarker.TextLoc);
oTgtDoc.TextSelection = oTR;
//$.bp(true);
return oTR;
}
}
oTL = oMarker.TextLoc; // attention - potential loop !!!!!!!
oTRfound = oTgtDoc.Find(oTL, oFindParams);
}
} //--- end FollowXRef
function GetFindParameters (iType, sSearch) { //=== set up parameters for various find actions
// Arguments iType: what find to be performed
// 3 Marker of type sSearch
// 8 Cross reference sSearch forwared
// sSearch: what to search for
// Returns Parameters for the find method
// Called by xxx
// Reference FDK Function Reference, F_ApiFind(), https://forums.adobe.com/thread/961616
// Used in FMcalc, FMvars, FMgraph
var findParams, propVal;
findParams = new PropVals() ;
switch (iType) {
case 3: // ---------------------------------- find marker of type sSearch, don't wrap
propVal = new PropVal() ;
propVal.propIdent.num = Constants.FS_FindWrap ;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival = 0 ; // don't wrap
findParams.push(propVal);
propVal = new PropVal() ;
propVal.propIdent.num = Constants.FS_FindMarkerOfType;
propVal.propVal.valType = Constants.FT_String;
propVal.propVal.sval = sSearch;
findParams.push(propVal);
return findParams;
case 8: // ---------------------------------- find cross reference sSearch forwards
propVal = new PropVal() ;
propVal.propIdent.num = Constants.FS_FindWrap ;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival = 0 ; // don't wrap
findParams.push(propVal);
propVal = new PropVal() ;
propVal.propIdent.num = Constants.FS_FindXRefWithFormat;
propVal.propVal.valType = Constants.FT_String;
propVal.propVal.sval = sSearch;
findParams.push(propVal);
return findParams;
default:
alert ("GetFindParameters: Case " + iType + " is not defined");
return null;
}
} //--- end GetFindParameters