Skip to main content
rombanks
Inspiring
March 28, 2017
Answered

Framescript: Check for unresolved xrefs in a doc without loop

  • March 28, 2017
  • 1 reply
  • 1719 views

Hello fellows,

Is there a way to check whether a doc contains unresolved xrefs without the need to loop through each and every xref and check its status?

What I'd like to do is to state "if there are no broken xrefs in doc, <do xyz>" or "if all xrefs are alive, <do xyz>". 🙂

Thank you in advance!

This topic has been closed for replies.
Correct answer frameexpert

Hi Jang,

Thank you for your response!

I don't understand how "oXRef.XRefIsUnresolved = true" can end this loop. I was sure the loop will continue as long as oXRef.ObjectValid( ) is true. BTW, isn't the "return false;" supposed to come after "else" (that doesn't appear in your example)?

Thanks,

Roman


Jang, Roman is using FrameScript and FrameScript functions don't have a return statement that immediately exits the function like ExtendScript does. Instead, FrameScript functions return a built-in "Result" variable that you can set as the return value of the function. In FrameScript, you would do something like this:

Function DocHasUnresolvedXRefs oDoc

//

Local Result(0), oXRef(0);

Set oXRef = oDoc.FirstXRefInDoc;

Loop While(oXRef)

  If oXRef.XRefIsUnresolved = 1

    Set Result = 1;

    LeaveSub; // Exit the function.

  EndIf

  Set oXRef = oXRef.NextXRefInDoc;

EndLoop

//

EndFunc

You can call this function with something like this code like this:

If DocHasUnresolvedXRefs{oDoc} = 1

  // Document has unresolved cross-references.

Else

  // No unresolved cross-references.

EndIf

-Rick

1 reply

4everJang
Legend
March 28, 2017

Hi Roman,

Checking "each and every xref" in a document is not such a big deal in scripting, as they are all connected in a linked list. Using any of the FM methods to check this is doing even more: it tries to update all the xrefs and then it knows which ones are unresolved. To show how easy it is, I have coded this utility function.

function hasUnresolvedXRefs( oDoc )

{

     var oXRef = oDoc.FirstXRefInDoc;

     while( oXRef.ObjectValid( ) )

     {

          if( oXRef.XRefIsUnresolved ) return true;

          oXRef = oXRef.NextXRefInDoc;

     }

     return false;

}

Note that this does not try to update XRefs, so you are checking the status of the XRefs the last time FM tried to update them.

rombanks
rombanksAuthor
Inspiring
March 28, 2017

Hi Jang,

Thank you for your response!

You are right - it is easy to loop through the xrefs. But I'd like to get the status not for each and every xref but for the whole oDoc - i.e., whether it contains at least one unresolved xref or not. Then, if it doesn't have any unresolved xrefs, do xyz. I hope that clarifies what I need to do.

Thanks again,

Roman

4everJang
Legend
March 28, 2017

That is exactly what my function does, as it only returns one single boolean value - the first unresolved XRef that is found will cause an immediate return of the value "true" and aborts the loop. Only if none of the XRefs is unresolved, a "false" value is returned. The built-in status property that you are looking for does not exist on the Doc level, but if it did, this code would be behind it.

You would use this function in your code as follows:

YourFunction ( oDoc )

{

     if( hasUnresolvedXRefs( oDoc )

     {

          /* do something with the unresolved XRefs or just report that the doc has some */

     }

     else

     {

          /* no unresolved XRefs - do something else with the Doc */

     }

}