Skip to main content
rombanks
Inspiring
January 26, 2017
Answered

Framescript: Retrieving text from a broken xref

  • January 26, 2017
  • 2 replies
  • 10677 views

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!

This topic has been closed for replies.
Correct answer frameexpert

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!


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

Display oXRef.TextRange.Text;

Rick

2 replies

Participant
March 3, 2022

I have Framescript version 5 which was compatible with FM10.

It was mainly used to generate table and cross-reference.

Once the template look and feel was changed it is not working.

Please help.

 

Regards,

NIshaa

Legend
January 27, 2017

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

Legend
January 27, 2017

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.

frameexpert
Community Expert
Community Expert
January 27, 2017

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.