Copy link to clipboard
Copied
Dear friends,
My whole script now works fine with the exception of the XRef update after inserting a new XRef. It works correctly if the target of the XRef is in the same file as the XRef (oDoc == oTgtDoc). Both files are open at the time of the update - and the active document is that with the XRef (oDoc).
→ What may be the problem here?
The blue XRefs all work correctly and point to a separate file (\endnotes). Manual updating with the GUI is OK, but why does this not work in the script?
// --- Build new XRef and insert it at saved location
Fno_SelectParagraph (oDoc, oPgfNew); // Required
oTgtTL = new TextLoc (oPgfNew, 0);
Fno_RestoreLocation (oDoc, oUserLoc);
oTL = oUserLoc.txtRange.beg;
oXRef = Fno_InsertXRef (oDoc, oTL, sXRefFmt, oTgtDoc, oTgtTL);
oDoc.UpdateXRefs(Constants.FF_XRUI_EVERYTHING); // note done in book files !!!!!!!!!!
alert ("UpdateXRefs error: " + FA_errno);
// --- Jump to the empty Endnote -----------------------
Fno_FollowXRef (oDoc, oXRef);
oENloc = Fno_SaveCurrentLocation (oTgtDoc);
Fno_RestoreLocation (oTgtDoc, oENloc);
oUserLoc = oENloc.txtRange.end;
oUserLoc.offset += 1; // go behind the marker.
oTgtDoc.TextSelection = new TextRange (oUserLoc, oUserLoc);
} //--- end Fno_InsertEndnote
// --- Build new XRef and insert it at saved location
Fno_SelectParagraph (oDoc, oPgfNew); // Required
oTgtTL = new TextLoc (oPgfNew, 0);
Fno_RestoreLocation (oDoc, oUserLoc);
oTL = oUserLoc.txtRange.beg;
oXRef = Fno_InsertXRef (oDoc, oTL, sXRefFmt, oTgtDoc, oTgtTL);
oDoc.UpdateXRefs(Constants.FF_XRUI_EVERYTHING); // note done in book files !!!!!!!!!!
alert ("UpdateXRefs error: " + FA_errno);
// --- Jump to the empty Endnote -----------------------
Fno_FollowXRef (oDoc, oXRef);
oENloc = Fno_SaveCurrentLocation (oTgtDoc);
Fno_RestoreLocation (oTgtDoc, oENloc);
oUserLoc = oENloc.txtRange.end;
oUserLoc.offset += 1; // go behind the marker.
oTgtDoc.TextSelection = new TextRange (oUserLoc, oUserLoc);
} //--- end Fno_InsertEndnote
Copy link to clipboard
Copied
I have not found a cure for this problem - but a bypass:
After typing the endnote text at the provided location the user may want to verify the location where he/she set the insert point for the XRef to the endnote.
Hence I decided to provide a function (an extended GoBack) with short cut ESC q n b. In this function I issue a KB simulation to open the Update References dialogue. IMHO the user knows what to do here (at least after reading my documentation...).
// GoToInsertPoint.jsx
#target framemaker
A_GoToInsertPoint (); // normally invoked by ESC q n b
function A_GoToInsertPoint () { // === to be integrated into Fnotes ===============================
var oDoc, oUserLoc, fcode = [];
oUserLoc = goFno.oSavedLocation; // saved in Fno_InsertEndnote
Fno_RestoreLocation (oUserLoc);
oDoc = app.ActiveDoc;
Fno_UpdateRefDlg ();
} //--- end A_GoToInsertPoint
function Fno_UpdateRefDlg () { // === open dialgoue Edit > Update References ======================
// oDoc.UpdateXRefs(Constants.FF_XRUI_EVERYTHING); // does not update a book file!
// Reference <Command Update
// <ReservedLabel Book Update &Book...>
// <ReservedLabel Document Update &References...>
// <KeySequence \!eU>
// <KeySequence \!fg>
// <Definition \x3E1>>
var fcode = [];
fcode[0] = 0x3E1; // there is no constant for this
Fcodes(fcode);
} //--- end Fno_UpdateRefDlg
function Fno_RestoreLocation (oLocation) { //=== Restore current location =========================
// Arguments oLocation: object created by Fno_SaveCurrentLocation
// Called by xxx
// Attention Not tested what happens if this document is no more open at restore
// Reference Rick Quatro at https://forums.adobe.com/thread/2243878
var oDoc, oPgf, tLoc, textRange;
oDoc = oLocation.doc
app.ActiveDoc = oDoc;
oDoc.CurrentPage = oLocation.page;
oPgf = oLocation.pgf;
if (oPgf.ObjectValid () === 1) {
oDoc.TextSelection = oLocation.txtRange;
}
textRange = oLocation.txtRange;
oDoc.ScrollToText(textRange);
} //--- end Fno_RestoreLocation
Copy link to clipboard
Copied
I did this check:
// UpdateXRefs.jsx
#target framemaker
main ();
function main () {
var oDoc = app.ActiveDoc;
oDoc.UpdateXRefs(Constants.FF_XRUI_EVERYTHING); // does not update a book file, even if no book is open!
}
Copy link to clipboard
Copied
IMHO this misbehavior of UpdateXRefs is a bug, hence I issued a bug report: FRMAKER-6893
In a book file where a XRef to another file has been inserted by a script, this XRef is not updated by function UpdateXRefs.
Steps to Reproduce:
Expected Result:
Function UpdateXRefs does what is says!
Any Workarounds:
Use the GUI (Edit > Update References) to update the references in the file bookfile_2en.fm