4 Replies Latest reply: Jul 22, 2014 1:26 AM by twoclicks RSS

    .FirstXRefInDoc not working

    twoclicks

      Hello,

      I try to parse xrefs in a doc (and update them), but I have trouble getting the reference to fist xref.

      var comp = doc.FirstXRefInDoc;

      returns undefined, although there are xrefs in a file. I work in FM 10.

      also global update doc.UpdateXRefs does not seem to have any effect.

      When I do manualy Edit - Update references, xrefs in document get updated. Are these properties and methods tied to FM11, in that case, what options I have in FM10?

        • 1. Re: .FirstXRefInDoc not working
          frameexpert Community Member

          I tried the code below in FrameMaker 10 and it gives me the first cross-reference in my document. However, the UpdateXRefs() method does not appear to work.

           

          #target "framemaker-10.0"
          
          var doc = app.ActiveDoc;
          var xref = doc.FirstXRefInDoc;
          
          alert (xref);
          
          doc.UpdateXRefs (Constants.FF_XRUI_FORCE_UPDATE);
          

           

          Rick

          • 2. Re: .FirstXRefInDoc not working
            twoclicks Community Member

            Indeed, you are right, doc.FirstXRefInDoc really returns Xref object, I was misled by line number that returned the undefined error, also thanks to this I was able to eliminate the real source of this particular error: I tried to get the next Xref by calling doc.NextXrefInDoc, but while FirstXrefinDoc is a property of Doc, NextXrefInDoc is a property of particular Xref, hence the undefined error. In your code, xref.NextXrefInDoc would return next cross-reference. Now I am able to traverse through all cross-references in doc.

             

            However, the core of the problem persists - neither doc.UpdateXRefs, nor xref.UpdateXRef seems to be doing anything, Although the cross-references do not manifest themselves in Framemaker as unresolved (they point to a correct document and are "green" in cross-reference panel) calling update does not refresh their text (e.g.: page 14) - it is empty and only gets populated when I manualy select Edit - Update References.

            When saved as mif file, these strange cross-references do not have <XRefLastUpdate> property (not even after calling doc.UpdateXRefs). This property is only generated after the mentioned manual process. So what  really need is something that triggers the same process that populates those xrefs. Maybe it is not UpdateXRef, however I can not find anything analogous in documentation.

             

            Thanks for your help so far

            • 3. Re: .FirstXRefInDoc not working
              Russ Ward Community Member

              Hi,

               

              I tried the UpdateXRefs() call with Constants.FF_XRUI_FORCE_UPDATE and got the same results. But, it seems to work with FF_XRUI_EVERYTHING. Try that.

               

              doc.UpdateXRefs (Constants.FF_XRUI_EVERYTHING);

               

              That's the constant I've used in my FDK plugins with success.

               

              Russ

              • 4. Re: .FirstXRefInDoc not working
                twoclicks Community Member

                Neither

                doc.UpdateXRefs (Constants.FF_XRUI_EVERYTHING);

                works in my situation, but I have found out why and will record it here for future generations

                 

                Updating of references does not work, when the document is opened from  mif file and unsaved as fm. (I somehow thought that opened documents are equal, regardes of their representation on hard drive, clearly there are some exceptions.)

                 

                So my above problem is then actualy solved without any need co call UpdateXRefs, now my script saves the opened doc as temporary fm file, closes the mif, opens the temporary fm file (here those strange semi-working references get updated to normal xrefs) and then saves this file as original mif (as I need the mif for further processing outside fm).

                 

                Thank you both guys for your suggestions, they nudged me out of circular thinking and helped me to find this out.