• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Framescript: Check for unresolved xrefs in a doc without loop

Participant ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

790

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
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 28, 2017 Mar 28, 2017

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; // Ex

...

Votes

Translate

Translate
Advocate ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Participant ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Advocate ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

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

     }

}

Votes

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
community guidelines
Participant ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Advocate ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

No, return breaks the loop and immediately returns the value to the calling code. I use this feature all the time in my code: checking for all kinds of error conditions, returning false whenever an error condition is found. This allows for much cleaner code than having to make huge nested if else constructs.

Votes

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
community guidelines
Community Expert ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Advocate ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

Didn't know that. I have not touched FrameScript since FrameMaker 10 introduced ExtendScript. Thanks for pointing this out and helping Roman along.

Votes

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
community guidelines
Participant ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

Rick, Jang,

Thanks a lot for your input!

Rick, I didn't realize we can define functions in Framescript, like in Extendscript. I thought we can only define sub-routines and then run them.

Thanks,

Roman

Votes

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
community guidelines
Community Expert ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

Roman, You have to work to master your language or else you will continue to struggle with the simplest tasks. -Rick

Votes

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
community guidelines
Participant ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

Hi Rick,

You are right. That's what I am trying to do. I am using the Framescript Reference Guide and this forum to master it.  I don't have any other source of information. It's interesting as the Framescript Reference Guide doesn't even mention functions -- only the sub-routines. Maybe it's the matter of Framescript version?

I am using v.5.2.

Thanks,

Roman

Votes

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
community guidelines
Participant ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

I've noticed that the Framescript 6 Guide mentions user-defined functions vs. sub-routines. Have the user-defined functions been introduced in the latest version of Framescript? Or maybe, the user-defined functions were supported by earlier versions but not documented?

Thanks,

Roman

Votes

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
community guidelines
Community Expert ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

Hi Roman,

I have FrameScript 5.2 and 6.0 installed. The user guides of both versions describe user functions (section "Writing Scripts").

I do not remember, when user functions were introduced, but I am sure that they were always described.

The FrameScript mailing list is mainly for FrameScript. In the past there was more traffic, but many moved to ExtendScript. However, you can still search the archive to find valuable info.

This Adobe forum is mainly for ExtendScript.

Rick Quatro had published a book about learning FrameScript a couple of years ago. With this book I learned to master FrameScript. As far as I know this book is out of print now.

Best regards

Winfried

Votes

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
community guidelines
Participant ,
Mar 29, 2017 Mar 29, 2017

Copy link to clipboard

Copied

Hi Winfried,

I appreciate your response! Unfortunately, I couldn't find the v5.2 user guide. I only have a scriptwriter's guide, which doesn't mention user functions -- only the subroutines.

Yes, I've also noticed that the Framescript mailing list is gradually phasing out. I wonder if someone ever thought of creating an online Framescript course. I am sure many people would jump on this opportunity to learn the language.

Best regards,

Roman

Votes

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
community guidelines
Community Expert ,
Mar 29, 2017 Mar 29, 2017

Copy link to clipboard

Copied

Hi Roman,

If you are only interested in an old user guide, then you might install an old version without activating it. In the installation folder there should be a doc folder with all the documentation.

Here are installation files for old versions:

http://www.framescript.eu/download/

Best regards

Winfried

Votes

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
community guidelines
Participant ,
Mar 29, 2017 Mar 29, 2017

Copy link to clipboard

Copied

LATEST

Hi Winfried,

Got it. Thank you!

Best Regards,

Roman

Votes

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
community guidelines