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

Script : how to retrieve an autonum content of an XRef ?

New Here ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

Hi,

In FM2022, I'm trying to retrieve via a script the text of all XRef of a document. The problem is, the content is an autonumbering ($paranum) and, for every note, the property XRefSrcText contains only the Unique ID (no ":" inside, as supposed, so no source file, and no content text). I can access the source file via the property XRefFile, but not the text (even via the method GetText(), but I'm not sure I understand this one correctly). By the way, all the references are resolved and displaying the right number in FM.

I know that it is not supposed to be done, since it's a number generated by Framemaker, but my client wants it writen in the XML export as it is in the PDF export...

 

Thanks in advance for any help !

Xavier

TOPICS
Scripting

Views

199

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 , Jan 20, 2023 Jan 20, 2023

An XRef object will have a TextRange property. You can use this function to get the text from the TextRange. You can call it like this (where xref is your XRef object and doc is your Doc object):

 

xrefText = getText (xref.TextRange, doc);

function getText (textObj, doc) {

    // Gets the text from the text object or text range.

    var text = "", textItems, i;
    
    // Get a list of the strings in the text object or text range.
    if (textObj.constructor.name !== "TextRange") {
        te
...

Votes

Translate

Translate
Community Expert ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

I am not a scripter, nor do I play one on TV. However, FM has a Cross-References pod that can show you all the cross-references, with page numbers, of the current file or all the open files. Maybe you can use that as a place to pull page numbers from?

xrefs-pod.png

 

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 ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

An XRef object will have a TextRange property. You can use this function to get the text from the TextRange. You can call it like this (where xref is your XRef object and doc is your Doc object):

 

xrefText = getText (xref.TextRange, doc);

function getText (textObj, doc) {

    // Gets the text from the text object or text range.

    var text = "", textItems, i;
    
    // Get a list of the strings in the text object or text range.
    if (textObj.constructor.name !== "TextRange") {
        textItems = textObj.GetText(Constants.FTI_String);
    } else {
         textItems = doc.GetTextForRange(textObj, Constants.FTI_String);
    }
    // Concatenate the strings.
    for (i = 0; i < textItems.len; i += 1) {
        text += (textItems[i].sdata);
    }
    return text; // Return the text
}

 

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
New Here ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

Thanks a lot ! It works.

Though I'd like to understand this one :

- Any clue on why the XRefSrcText property doesn't contain the text nor the source file, and why the GetText method does not give anything in this case ?

- In my case, is it right that your function is always in the case :

textObj.constructor.name == "TextRange"

?

 

Best regards,

Xavier

 

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 ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

LATEST

For an unstructured cross-reference, the XRefSrcText property will be a direct match to the text of the corresponding Cross-Ref marker. When you insert a cross-reference through the interface, FrameMaker creates a value that is a combination of the target paragraph format, text, and a unique id. This ensures that Cross-Ref markers are unique throughout a document. Once this value is created, it does not change, regardless of changes you make to the target paragraph for paragraph format.

 

Yes, my function will take a text object (Pgf, Element, TextFrame, etc.) or a TextRange. In your case, you are passing in the TextRange property of the XRef object.

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