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
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
...
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?
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
}
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
Copy link to clipboard
Copied
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.