32 Replies Latest reply on Mar 1, 2017 5:27 PM by rombanks

    Framescript: Retrieving text from a broken xref

    rombanks Level 1

      Hello fellows,

       

      I'd like to write a script that will find broken external xrefs and attempt to restore them.  In my case, the xrefs get broken because the xref markers appearing in the source files are often updated by a system that generates these source files. I'd like to restore the xrefs by retrieving the xref string and attempting to find this string in the source files. But here is a problem: when an xref is broken, it no longer allows to retrieve XRefSrcText properly. The xref string no longer appears in XRefSrcText. I used the following code to test that:

       

      Set vCurrentDoc = ActiveDoc;

      Set vXRef = vCurrentDoc.FirstXRefInDoc;

       

      Loop While(vXRef)

      If vXRef.XRefIsUnresolved

      Write Console  vXRef.XRefSrcText;

       

      EndIf

      Set vXRef = vXRef.NextXRefInDoc;

      EndLoop

       

      So, the XRefSrcText of an unresolved xref appears as follows:

      25117: TableTitleTable Entry: ;2511718;2511719

       

      While the XRefSrcText  of a live xref  appears as follows:

       

      41369: TableTitle: Table 329: Item Numbering

       

      What I would need to extract from here is the string "Item Numbering" and then find it in the xref source file to create a new link.

       

      My question is how can one retrieve the text string from a broken xref? One way I could think of is converting the xrefs to text, copying the relevant part into a variable using regex. Any other ideas?

       

      Thank you!

        • 1. Re: Framescript: Retrieving text from a broken xref
          Russ Ward Level 4

          Hi rombanks,

           

          Interesting question. If you have to resort to conversion to text, I would copy xrefs into another "scratch pad" document, then convert to text. Seems messy to do it in the original doc.

           

          What is that first number in the XRefSrcText string, like 25117? The docs don't explain what it is, that I can find. Does that point to anything?

           

          Russ

          • 2. Re: Framescript: Retrieving text from a broken xref
            Russ Ward Level 4

            One other thought... I would expect the XRefSrcText string to stay static, until an update attempt. Do you have these files set to automatically update xrefs when they are opened? I'm a little fuzzy in this area, so maybe this is not useful.

            • 3. Re: Framescript: Retrieving text from a broken xref
              frameexpert Level 4

              The XRefSrcText string does stay the same, whether the cross-reference is resolved or not. The cross-reference is unresolved because the Cross-Ref marker with the matching text is missing (or the target file is missing or has been renamed). What Roman is trying to do (I think) is grab the actual cross-reference text (for example, See "Installation" on page 1) and trying to do a match on that. Sometimes that text will be missing for an unresolved cross-reference.

               

              As I read Roman's original post, I think he may be misunderstanding the XRefSrcText property. The value of this property needs to match the value of the Cross-Ref marker that it is pointing to. As I said above, this property doesn't change if a cross-reference becomes unresolved.

               

              It seems to me that the problem is with the process that creates the source files. One solution may be to have this process also create Cross-Ref markers in the source documents that will have fixed text. You will have to make sure that each Cross-Ref marker's text is unique, but then the cross-references would still be resolved even after new source files are generated.

              • 4. Re: Framescript: Retrieving text from a broken xref
                rombanks Level 1

                Rick, Russ,

                Hi!

                 

                I appreciate your response!

                 

                After running additional tests, I saw that even some resolved xrefs don't include their corresponding xref text string in their XRefSrcText -- Rick is right.

                I also agree with Rick that the generated source files should have included static xref markers. Unfortunately, that's not the case and this is not going to change. That's the main source of the problem. So, I'll have to create a workaround. As far as I can see, the only way to do so is to convert each unresolved xref to text, extract the target xref text (using regex), delete the rest, search for a matching string in the xref source file, and create a new xref if possible. For some reason, I can't find a Framescript command that converts an xref to plain text. Please, advise!

                 

                Thanks,

                Roman

                • 5. Re: Framescript: Retrieving text from a broken xref
                  frameexpert Level 4

                  Hi Roman. Try this.

                   

                  // Assuming oDoc is your document object and oXRef is the cross-reference you want to "flatten".
                  // Create a temporary Cross-Reference format.
                  New XRefFmt Name('~temp~') DocObject(oDoc) NewVar(oXRefFmt);
                  Set oXRefFmt.Fmt = oXRef.XRefFmt.Fmt;
                  // Assign the temporary Cross-Reference format to the Cross-Reference.
                  Set oXRef.XRefFmt = oXRefFmt;
                  // Now delete the temporary format, which should "flatten" the Cross-Reference.
                  Delete Object(oXRefFmt);
                  

                   

                  I haven't tested the code above, but I have used this technique successfully. Note that you can use this same method to flatten user variables. Please let me know if you have any questions or comments. -Rick

                  • 6. Re: Framescript: Retrieving text from a broken xref
                    rombanks Level 1

                    Hi Rick,

                     

                    I appreciate your response and the code sample! It indeed converts the xref to plain text.

                    However, the current problem is that the code doesn't select the xref first. I need the xref to be selected to extract the relevant text string once the xref becomes plain text and then delete the xref text.

                     

                    So, I tried to select the xref and retrieve its text, as follows:

                     

                    Set oDoc = ActiveDoc;

                    Set oXRef = oDoc.FirstXRefInDoc;

                    New TextRange NewVar(vXrefRange) Object(oXRef)

                    Offset(0) Offset(oXRef.Size);

                    Set oDoc.TextSelection = vXrefRange;

                    Display vXrefRange.Text;

                     

                    So, the xref is selected, but its text is not retrieved/displayed for some reason.

                    The text is only displayed if I write "Display oDoc.TextSelection.Text;" instead.

                     

                    What am I missing?

                     

                    Thank you!

                    • 7. Re: Framescript: Retrieving text from a broken xref
                      frameexpert Level 4

                      You don't need to make a text range object; an XRef already has one.

                       

                      Display oXRef.TextRange.Text;

                       

                      Rick

                      • 8. Re: Framescript: Retrieving text from a broken xref
                        rombanks Level 1

                        Hi Rick,

                         

                        Thank you for your valuable input!

                         

                        I've just noticed that too, while checking the Reference Guide.

                         

                        Thanks,

                        Roman

                        • 9. Re: Framescript: Retrieving text from a broken xref
                          rombanks Level 1

                          I wonder if it is possible to access the xref building blocks. For example, is there a way to retrieve the <$paratext> text of the xref?

                          As per the Reference Guide, there is only a way to retrieve the building blocks as a string.

                           

                          Thanks,

                          Roman

                          • 10. Re: Framescript: Retrieving text from a broken xref
                            4everJang Level 3

                            Hello Roman,

                             

                            The XRefSrcText property contains the paragraph text, preceded by identification info. When referencing a structured element, this identification is the element ID plus element tag name. In unstructured FM, it is the paragraph ID plus the paragraph tag name (the name of the paragraph format).

                             

                            To get the referenced paratext, search for the last occurrence of the : character in XRefSrcText and use whatever follows it. Note that this text is only replaced when the XRef is resolved. Unresolved cross-refs will not show any paratext.

                             

                            PS. If you are working in structured FM, you should really get the XRef Wizard from Russ Ward - its $35 price tag is dirt cheap for what it does.

                             

                            Good luck

                             

                            Jang

                            • 11. Re: Framescript: Retrieving text from a broken xref
                              4everJang Level 3

                              Hello Roman,

                               

                              The XRefSrcText property contains the paragraph text, preceded by identification info. When referencing a structured element, this identification is the element ID plus element tag name. In unstructured FM, it is the paragraph ID plus the paragraph tag name (the name of the paragraph format).

                               

                              To get the referenced paratext, search for the last occurrence of the : character in XRefSrcText and use whatever follows it. Note that this text is only replaced when the XRef is resolved. Unresolved cross-refs will not show any paratext.

                               

                              PS. If you are working in structured FM, you should really get the XRef Wizard from Russ Ward - its $35 price tag is dirt cheap for what it does.

                               

                              Good luck

                               

                              Jang

                              • 12. Re: Framescript: Retrieving text from a broken xref
                                rombanks Level 1

                                Hi Jang,

                                 

                                Thank you for joining the discussion!

                                 

                                I am using unstructured FM.

                                In my case, the XRefSrcText doesn't contain the paratext, even if an xref is resolved. That's because the xref source text has a custom xref marker.

                                 

                                I wondered if the xref format's <$paratext> element can be somehow accessed to retrieve its value. Theoretically, this should have been possible, but based on what I see in the Framescript Ref. Guide, it's not.

                                 

                                Regards,

                                Roman

                                • 13. Re: Framescript: Retrieving text from a broken xref
                                  4everJang Level 3

                                  Hi Roman,

                                   

                                  If the XRefSrcText does not contain the para text, I really don't know what your system has been up to. Are you sure they are FrameMaker cross-references and not hyperlihks?

                                   

                                  If they are true XRefs (or even if they are not - if they turn out to be hypertext links), and there is some text visible in them in FM, you can always retrieve that text. Assuming you have your active document in variable oDoc, try this at home:

                                   

                                  var oXRef = oDoc.FirstXRefInDoc;

                                  var oaTextItems = oXRef.GetText( Constants.FTI_String );

                                  var sText = "";

                                  var i;

                                  for( i = 0; i < oaTextItems.length; i++ )

                                  {

                                       sText += oaTextItems[i].sdata;

                                  }

                                  alert( sText );

                                   

                                  Then you will have to figure out how to pull the text without the page number etc. from that string and find that text in the target document. That is up to you to code.

                                   

                                  Ciaoi

                                   

                                  Jang

                                  • 14. Re: Framescript: Retrieving text from a broken xref
                                    rombanks Level 1

                                    Hi Jang,

                                     

                                    Thanks for your input!

                                    These are paragraph xrefs. I create xrefs manually. With Framescript, you can easily retrieve the xref text with oXRef.TextRange.Text;.

                                    The tricky part comes next. It seems that the only way to retrieve the relevant string from the xref textrange is by using regex. I am not sure if Framescript v5.2 I have supports regex. I didn't see any info on that matter anywhere. The Find String command doesn't seem to include the regex option.

                                     

                                    What are my options? I deliberately tried to avoid messing up with extendscript as it's not documented well, but it seems that there is no other choice.

                                     

                                    Thanks,

                                    Roman

                                    • 15. Re: Framescript: Retrieving text from a broken xref
                                      frameexpert Level 4

                                      You can get regular expression support in FrameScript 5.2 by using the VBScript.RegExp COM object built into most versions of Windows. Here is how you can use a regular expression to test the selected text:

                                       

                                      Set sText = TextSelection.Text;
                                      
                                      Set oRegex = InitializeXObject{'VBScript.RegExp'};
                                      If oRegex = 0
                                        Write Console 'VBScript.RegExp object could not be initialized.';
                                        LeaveSub;
                                      EndIf
                                      // This is the regular expression pattern.
                                      // These use the JavaScript RegExp syntax.
                                      Set oRegex.Pattern = '[\xd0\xd1\x2d]';
                                      // These flags are optional.
                                      Set oRegex.Global = True; // Default is True
                                      Set oRegex.IgnoreCase = True; // Default is True.
                                      
                                      Display oRegex.Test{sText};
                                      If oRegex.Test{sText} = 1
                                        Set oMatches = oRegex.Execute{sText};
                                        Loop While(i < oMatches.Count) LoopVar(i) Init(0) Incr(1)
                                          Display oMatch[i].Value; // Match value.
                                          Display oMatch[i].FirstIndex; // Offset from beginning of string.
                                        EndLoop
                                      EndIf
                                      
                                      Delete Object(oRegex);
                                      
                                      Function InitializeXObject sProgId
                                      //
                                      // Initializes and returns an EActiveXObject if it exists, or 0 (zero) if
                                      // it doesn't exist.
                                      
                                      Local Result(0);
                                      
                                      // Create the object.
                                      New EActiveXObject NewVar(Result) ProgId(sProgId);
                                      If Result.ErrorCode <> 0
                                        Write Console sProgId + ' could not be initialized.';
                                        Write Console 'ErrorCode: '+Result.ErrorCode;
                                        Set Result = 0;
                                      EndIf
                                      //
                                      EndFunc //--------------------------------------------------------------------
                                      

                                       

                                      There is way to get matching groups and you can do replacements. For more details, google VBScript regular expressions. Or ask me here.

                                       

                                      --Rick

                                      • 16. Re: Framescript: Retrieving text from a broken xref
                                        frameexpert Level 4

                                        Here is a link to a chapter from my out-of-print FrameScript book:

                                         

                                        http://www.rickquatro.com/resources/RegularExpressions.pdf

                                        • 17. Re: Framescript: Retrieving text from a broken xref
                                          4everJang Level 3

                                          I moved away from FrameScript as soon as ExtendScript became available. Not that I think FrameScript is not a decent product, but the clients I worked for always had trouble ordering even the smallest add-on for Frame, and ExtendScript does not require any additional installs. That is a decisive benefit in a world that is ruled by paranoiac (and often lazy) software security departments.

                                          • 18. Re: Framescript: Retrieving text from a broken xref
                                            rombanks Level 1

                                            Hi Rick,

                                             

                                            This is definitely a very interesting regex workaround. I greatly appreciate your guidance!

                                            I need to do my homework first -- look into the regex syntax.

                                             

                                            Thanks,

                                            Roman

                                            • 19. Re: Framescript: Retrieving text from a broken xref
                                              rombanks Level 1

                                              Hi Jang,

                                               

                                              I am not against using Extendscript, although it is still buggy in some cases (e.g., event scripts). The worst thing is that several years have passed since Extendscript had been released, and its documentation is still in horrible state. It's still too concise, misleading, lacking details and examples. Adobe did a very bad job in this area, as if they are not interested in having their customers use Extendscript.

                                               

                                              Regards,

                                              Roman

                                              • 20. Re: Framescript: Retrieving text from a broken xref
                                                frameexpert Level 4

                                                I am a big fan of FrameScript, having built my business around it since the late 1990s. It does allows you to do some interesting and powerful things through its EActiveXObject object:

                                                 

                                                * Work with regular expressions via VBScript.RegExp

                                                * Work with XML using MSXML

                                                * Work with Excel and Word through their COM interface

                                                 

                                                There are now native ways of working with regular expressions and XML, but I still find the EActiveXObject approach easier, mainly because I have so much existing code that I can reuse (over 6,000 scripts).

                                                 

                                                FrameScript also has ODBC support for working directly with databases. The developer, Frank Elmore, has always been responsive to help requests, suggestions, and feature requests. Although FrameScript rides on top of the FDK (like ExtendScript), Frank has done a good job of hiding some of the FDK "ugliness" and providing shortcuts for commonly used tasks (like displaying an object's properties).

                                                 

                                                On the other hand, there is a lot to like about ExtendScript, especially its dialog box model, native XML/XPath support, and the fact that it is built into FrameMaker. Also, since it is based on JavaScript, there are a lot more ways to learn the language. The majority of my script work over the last couple of years has been with ExtendScript instead of FrameScript.

                                                 

                                                One thing that can help you cope with the lack of ExtendScript documentation is the FDK documentation. The FDK examples are in C, but they give you a good overview of the FrameMaker object model and you can learn to translate the C examples into ExtendScript.

                                                 

                                                -Rick

                                                • 21. Re: Framescript: Retrieving text from a broken xref
                                                  rombanks Level 1

                                                  Hi Rick,

                                                   

                                                  Thank you for sharing your insights on these 2 languages.

                                                  You've definitely been one of the prominent pioneers in this field, and thank you for your great and invaluable contribution to the Framers' community!

                                                   

                                                  Best Regards,

                                                  Roman

                                                  • 22. Re: Framescript: Retrieving text from a broken xref
                                                    rombanks Level 1

                                                    Hello fellows,

                                                    I took some time to play with regex and think how to implement the xref fixing procedure.

                                                    While testing my regex, I encountered the following problem. Let's say I have a string <Text Goes Here> that is the 1st string on the line and I'd like to match it using regex. I guess there are a couple of options syntax-wise to do it. One is ^<([^<>]*?)>.

                                                    So, when I run this regex query in FM, it matches <Text Goes Here>. But when I add it to my code, the script fails to match the string. I can't figure out why.

                                                    When I set oRegex.Pattern = '^<([^<>]*?)>'; the string is not found.

                                                     

                                                    My additional question is how to match Text Goes Here in <Text Goes Here> (without the angle brackets). AFAIK, this can be done using the lookaround technique but I didn't manage to create a matching query so far. Theoretically, it should be (?<=(<))[\w\s+])(?=(>)) but it doesn't match anything.

                                                     

                                                    Thank you for your input in advance!

                                                    • 23. Re: Framescript: Retrieving text from a broken xref
                                                      frameexpert Level 4

                                                      The VB.Script RegExp syntax is based on JavaScript regular expressions and lookbehind is not supported.

                                                       

                                                      I might need to see your code to see why the pattern doesn't match in your script.

                                                      • 24. Re: Framescript: Retrieving text from a broken xref
                                                        rombanks Level 1

                                                        Hi Rick,

                                                         

                                                        Thank you for your response!

                                                        Lack of lookaround support is bad news. What are the alternatives in this case?

                                                         

                                                        Here is the code part that deals with the relevant string match and extraction, before the new xref is created.

                                                        Set oDoc = ActiveDoc;

                                                        Set oXRef = oDoc.FirstXRefInDoc;

                                                         

                                                        New EActiveXObject ProgId('VBScript.RegExp') NewVar(oRegex);

                                                        If oRegex.ErrorCode <> 0

                                                        MsgBox 'The VBScript.RegExp object could not be initialized.';

                                                        LeaveSub;

                                                        EndIf

                                                         

                                                        Loop While(oXRef)

                                                            If oXRef.XRefIsUnresolved

                                                                Set vXrefTxt = oXRef.TextRange.Text;

                                                                Set vXrefFmt = oXRef.XRefFmt.Name;

                                                                Set vXrefSrc = oXref.XRefFile;

                                                                NEW TextLoc NewVar(targetLoc) Object(oXref) Offset(oXref.Begin);

                                                              

                                                                If vXrefFmt = (("Table Entry and Table") | ("Table Entry") | ("Cell and Table"))

                                                                    Set oRegex.Pattern = '^<([^<>]*?)>';

                                                                ElseIf vXrefFmt = (("Catalog Name") | ("Catalog Name, Number, Page (short)"))

                                                                    Set oRegex.Pattern = '^.*(?=(\s)+(Catalog))';

                                                                EndIf

                                                               

                                                                Set oRegex.Global = False;

                                                                Set oMatches = oRegex.Execute{vXrefTxt};

                                                               

                                                                Loop While(i < oMatches.Count) LoopVar(i) Init(0) Incr(1)

                                                                  Set TrgtValue = oMatches[i].Value;

                                                                  //Display oMatches[i].Value;

                                                                EndLoop

                                                               

                                                                If TrgtValue = ''

                                                                 MsgBox 'No matches found.';

                                                                 LEAVELOOP;

                                                                EndIf

                                                        ...

                                                        • 25. Re: Framescript: Retrieving text from a broken xref
                                                          rombanks Level 1

                                                          Guys,

                                                           

                                                          Do you have any suggestions/remarks?

                                                           

                                                          Thank you!

                                                          • 26. Re: Framescript: Retrieving text from a broken xref
                                                            rombanks Level 1

                                                            After running some debug tests, I see that the offending code is the code that checks the xref Pgf format. Without it, the regexp works well.

                                                             

                                                            I changed the code to:

                                                             

                                                            If vXrefFmt == (('Table Entry and Table') | ('Table Entry') | ('Cell and Table'))

                                                                        Set oRegex.Pattern = '^<([^<>]*?)>';

                                                            ElseIf vXrefFmt == (('Catalog Name') | ('Catalog Name, Number, Page (short)'))

                                                                        Set oRegex.Pattern = '^.*(?=(\s)+(Catalog))';

                                                            EndIf

                                                             

                                                            But it still causes the regexp not to be matched. What's wrong with the IF part here?

                                                             

                                                            Thanks!

                                                            • 27. Re: Framescript: Retrieving text from a broken xref
                                                              rombanks Level 1

                                                              Hello again,

                                                               

                                                              I've resolved the issue above, it was just a matter of syntax.

                                                              The next hurdle I have is pretty strange. I can retrieve the target xref text's marker string and the target filename and store them in their variables.

                                                              But, when I try to create a new xref in place of the broken one and specify the new xref's XRefSrcText and XRefFile, I get the following error:

                                                               

                                                              Run Error (Read Only Variable on command SET at line 86 and line 87...

                                                               

                                                              Here is the old xref deletion and new xref creation code:

                                                               

                                                              Displaying = False;      

                                                              //Delete the old Xref and create a new one in target file;

                                                              SET ActiveDoc = objTarget;

                                                              NEW TextLoc NewVar(targetLoc) Object(oXref) Offset(oXref.Begin.Offset);

                                                              //Display targetLoc;

                                                              SET tempXRef = oXRef;

                                                              SET oXRef = tempXRef.NextXRefInDoc;

                                                              Delete Object (tempXRef);

                                                              NEW XRef Format(vXrefFmt) TextLoc(targetLoc) NewVar(vxrefVar);           

                                                              [Line 86] SET vxrefVar.XRefSrcText = vTrgtMarkerTxt;

                                                              [Line 87] SET vxrefVar.XRefFile = vXrefSrc;

                                                               

                                                              It is important to note that the vTrgtMarkerTxt and vXrefSrc values are the right ones (checked by displaying them).

                                                              Please, advise!

                                                              Thanks in advance!

                                                              • 28. Re: Framescript: Retrieving text from a broken xref
                                                                frameexpert Level 4

                                                                Hi Roman,

                                                                 

                                                                A few things of note here:

                                                                 

                                                                1) Test if the new Cross-Reference exists before trying to set its properties:

                                                                 

                                                                If vrefVar
                                                                  // Set the properties here (lines 87, 88)
                                                                Else
                                                                  Write Console 'Cross-reference was not inserted.';
                                                                EndIf
                                                                

                                                                 

                                                                2) There is no reason to explicitly create a TextLoc for the new cross-reference. You can simply do this:

                                                                 

                                                                Set targetLoc = oXRef.TextRange.Begin;
                                                                

                                                                 

                                                                3) It is not necessary to delete the old cross-reference and insert a new one. Simply change the properties on the old cross-reference:

                                                                 

                                                                Set oXRef.XRefSrcText = vTrgMarkerTxt;
                                                                Set oXRef.XRefFile = vXrefSrc;
                                                                

                                                                 

                                                                -Rick

                                                                • 29. Re: Framescript: Retrieving text from a broken xref
                                                                  rombanks Level 1

                                                                  Hi Rick,

                                                                   

                                                                  I appreciate your response and your helpful input!

                                                                  Question: Why defining targetLoc via a TextLoc is the wrong approach here?

                                                                   

                                                                  My biggest concern right now is that I can't figure out how to extract Text Goes Here from <Text Goes Here> using the regex, without the ability to use lookbehind. So far, after checking multiple discussions on the lookbehind alternatives, I haven't found any similar example. Do you have an idea how to drop the angle brackets from <Text Goes Here>?

                                                                   

                                                                  Thank you in advance!

                                                                  • 30. Re: Framescript: Retrieving text from a broken xref
                                                                    rombanks Level 1

                                                                    Here is the strangest thing:

                                                                     

                                                                    When I use the regexp ^<.*> in the FM search window, it finds <Text Goes Here> at the beginning of a line.

                                                                    When I do the same with the code, Display oMatches.Count returns 1, but the following code doesn't retrieve the matching value:

                                                                    Loop While(i <= oMatches.Count) LoopVar(i) Init(0) Incr(1)

                                                                          SET TrgtValue = oMatches[i].Value;

                                                                          Display TrgtValue;

                                                                    EndLoop

                                                                     

                                                                    In addition, how can I leave this loop and return to the main one in case there is no match?

                                                                     

                                                                    Thank you!

                                                                    • 31. Re: Framescript: Retrieving text from a broken xref
                                                                      rombanks Level 1

                                                                      Hello fellows,

                                                                       

                                                                      After a lot of experimenting, I have resolved the issues I had with my regex. The script can now find and extract the required text from the broken xrefs, loop through the broken links, but for some unclear reason, it fails to find the text in the source file and fix the corresponding xref. It is important to note that the text to which I'd like to link to is located either in a table caption or in a table cell.

                                                                      I went over the code line by line, and I don't see what can cause the script not to work. I obviously miss something. I hope you'll be able to point out where is problem is hiding. Here is the full code:

                                                                       

                                                                      SET oDoc = ActiveDoc;

                                                                       

                                                                      New EActiveXObject ProgId('VBScript.RegExp') NewVar(oRegex);

                                                                          If oRegex.ErrorCode <> 0

                                                                              MsgBox 'The VBScript.RegExp object could not be initialized.';

                                                                              LeaveSub; // Exit

                                                                          EndIf

                                                                            

                                                                      Loop ForEach(XRef) In(oDoc) LoopVar(vXRef)

                                                                          SET vXrefTxt = vXRef.TextRange.Text;

                                                                          SET vXrefFmt = vXRef.XRefFmt.Name; 

                                                                          SET vXrefSrc = vXRef.XRefFile;

                                                                       

                                                                      If (vXRef.XRefIsUnresolved)

                                                                                         

                                                                              If (vXrefFmt = 'Table Entry and Table') or (vXrefFmt = 'Table Entry') or (vXrefFmt = 'Cell and Table')

                                                                                  SET oRegex.Pattern = '^.+(?=(>))';

                                                                              ElseIf (vXrefFmt = 'Catalog Name') or (vXrefFmt = 'Catalog Name, Number, Page (short)')

                                                                                  SET oRegex.Pattern = '^.+Catalog';

                                                                              EndIf

                                                                            

                                                                              SET oRegex.Global = False;

                                                                                    

                                                                              SET oMatches = oRegex.Execute{vXrefTxt};     

                                                                          

                                                                              If (oMatches.Count > 0)

                                                                                  //Display oMatches.Count;

                                                                                  Loop While(i < oMatches.Count) LoopVar(i) Init(0) Incr(1)

                                                                                   SET vTrgtValue = oMatches[i].Value;

                                                                                   //Display vTrgtValue;

                                                                                  EndLoop

                                                                              Else

                                                                                 MsgBox 'No matches found.';

                                                                                 Write Console 'No matches found for: 'vXrefTxt;

                                                                                 LeaveLoop;

                                                                              Endif

                                                                            

                                                                              //Lookbehind issue workaround

                                                                              If (vXrefFmt = 'Table Entry and Table') or (vXrefFmt = 'Table Entry') or (vXrefFmt = 'Cell and Table')

                                                                                  Find String('<') InString(vTrgtValue) Backward ReturnPos(vPos);

                                                                                  //Drop the left bracket.

                                                                                  Get String FromString(vTrgtValue) StartPos(vPos+1)

                                                                                  NewVar(vTrgtValue);

                                                                                  Display vTrgtValue;

                                                                              EndIf

                                                                            

                                                                              SET objTarget = ActiveDoc;

                                                                              OPEN Document File(vXrefSrc);

                                                                              If vXrefSrc

                                                                                  SET objSource = ActiveDoc;

                                                                                  SET objDoc = objSource;

                                                                              Else

                                                                               MsgBox 'Cannot find' + vXrefSrc+'.';

                                                                              EndIf

                                                                       

                                                                              LOOP ForEach(Pgf) In(objDoc) LoopVar(pgfvar)

                                                                                  If (pgfvar.Page.ObjectName = 'BodyPage')

                                                                                      Find String(vTrgtValue)

                                                                                      InObject(pgfvar)

                                                                                      ReturnRange(vrangevar)

                                                                                      ReturnStatus(vfound)

                                                                                      ReturnString(vfoundstr);

                                                                                    

                                                                                      If vfound

                                                                                          If (pgfvar.Name == 'CellEntry') or (pgfvar.Name == 'TableTitleCatalog')

                                                                                              Get TextList NewVar(vMarkerList) MarkerAnchor InObject(pgfvar);

                                                                                        

                                                                                              If (vMarkerList.Count > 0)

                                                                                                  Get Member Number(1) From(vMarkerList) NewVar(vXRefBegin);

                                                                                                  SET vXRefType = vXRefBegin.TextData.MarkerTypeId.Name;

                                                                                                  If (vXRefType = 'Cross-Ref')

                                                                                                      SET vTrgtMarkerTxt = vXRefBegin.TextData.MarkerText;

                                                                                                      //Display vTrgtMarkerTxt;

                                                                                                  Endif

                                                                                              Endif

                                                                                        

                                                                                              Displaying = False;      

                                                                                              //Create XRef in target file;

                                                                                              SET ActiveDoc = objTarget;

                                                                                              SET vXRef.XRefSrcText = vTrgtMarkerTxt;

                                                                                              SET vXRef.XRefFile = vXrefSrc;

                                                                                                                              

                                                                                              //Update Xrefs and redisplay;

                                                                                              Update Xrefs OpenDocs ClosedDocs;

                                                                                              Displaying = True;

                                                                                              Update ReDisplay;

                                                                                              //LeaveLoop;           

                                                                                          EndIf

                                                                                        

                                                                                      Else

                                                                                          SET ActiveDoc = objTarget;

                                                                                          //Display vXrefTxt + 'not found in ' +vXrefSrc +'.';  

                                                                                          Write Console vXrefTxt + ' not found in ' +vXrefSrc +'.';

                                                                                          LeaveLoop;

                                                                                      EndIf

                                                                                               

                                                                                  EndIf

                                                                                  

                                                                              EndLoop     

                                                                        

                                                                          EndIf

                                                                        

                                                                      EndLoop

                                                                      Delete Object(oRegex);   

                                                                       

                                                                      Thank you in advance!

                                                                      • 32. Re: Framescript: Retrieving text from a broken xref
                                                                        rombanks Level 1

                                                                        Guys,

                                                                         

                                                                        Any ideas what could be wrong syntax-wise?

                                                                         

                                                                        Thank you in advance!