Highlighted

UpdateXRefs does not update

Advocate ,
Aug 06, 2019

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?

Xref-bookfile-not-updated.png

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

TOPICS
Scripting

Views

138

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

UpdateXRefs does not update

Advocate ,
Aug 06, 2019

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?

Xref-bookfile-not-updated.png

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

TOPICS
Scripting

Views

139

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 06, 2019 0
Advocate ,
Aug 07, 2019

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 07, 2019 0
Advocate ,
Aug 07, 2019

Copy link to clipboard

Copied

I did this check:

  1. Open the book file bookfile_2en.fm
  2. Close the book
  3. In bookfile_2en.fm use the script to create the empty endnote (this opens the endnote file by itself, as it is in the same directory as bookfile_2en.fm)
  4. Enter some text as endnote
  5. Activate the book file
  6. The cross references are not updated
  7. Run the following script
  8. The cross references are still not upated
  9. But of course they can be updated by Edit > Update References

// 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!

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 07, 2019 0
K.Daube LATEST
Advocate ,
Aug 07, 2019

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:

  • Use the files from the attached ZIP (put all fm(book files in the same directory)
  • In the book open the file bookfile_2en.fm
  • Optionally: close the book
  • In bookfile_2en.fm place the cursor anywhere except the title paragraph.
  • Run the script  InsertEndnote.jsx
  • → The script opens the file endnotes and create an empty endnote. The cursor is in this endnote just after the XRef marker ready to accept input. Type something.
  • Switch to the file bookfile_2en.fm where you see at the location which you chose a new XREF. 8 It's 'figure' is not correct, because the XRef were not upated.
  • Run the script UpdateXRefs.jsx
  • → The cross references are still not updated
  • But of course they can be updated by Edit > Update References

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 07, 2019 0