Copy link to clipboard
Copied
I want to do this:
After finding a cross-reference I have a Text Range of that x-ref. But how to get to the x-ref object?
IMHO there should be an object with propery XRefFmt
aTextItems = oDoc.GetTextForRange(oTR, Constants.FTI_XRefBegin);
is of no help here, as it just provides the text of the x-ref.
Hi Klaus, see if this helps you get started. -Rick
var doc, textRange, textList, xref;
// Set a variable for the active document.
doc = app.ActiveDoc;
// Set a variable for the selected text range in the document.
textRange = doc.TextSelection;
// Get a list of cross-references in the selected text.
textList = doc.GetTextForRange (textRange, Constants.FTI_XRefBegin);
// Make sure there is a cross-reference in the selection.
if (textList.length > 0) {
// Get the first cross-reference and d
...
Copy link to clipboard
Copied
Hi Klaus, see if this helps you get started. -Rick
var doc, textRange, textList, xref;
// Set a variable for the active document.
doc = app.ActiveDoc;
// Set a variable for the selected text range in the document.
textRange = doc.TextSelection;
// Get a list of cross-references in the selected text.
textList = doc.GetTextForRange (textRange, Constants.FTI_XRefBegin);
// Make sure there is a cross-reference in the selection.
if (textList.length > 0) {
// Get the first cross-reference and display its source text and format.
xref = textList[0].obj;
alert (xref.XRefSrcText);
alert (xref.XRefFmt.Name);
}
Copy link to clipboard
Copied
Thank You Rick for pointing me to the right direction!
First I tried this:
aTextItems = oDoc.GetTextForRange(oTR, Constants.FTI_XRefBegin);
if (aTextItems.len > 0) {
oXref = aTextItems[0].obj;
}
oXref.XRefFmt.Name = sName; // the new format name
oXref.XRefFmt.Fmt = sDef; // the new format definition
oDoc.UpdateXRef(oDoc, oXref); // Establish the new xref
But this works only partially: The x-ref in the doc is changed to the new format. but the x-ref format defintion becomes wrong: name: is the old one, definintion. is the new one. After all the old format is renamed to the new format in the catalogue!
This works as intended
aTextItems = oDoc.GetTextForRange(oTR, Constants.FTI_XRefBegin);
if (aTextItems.len > 0) {
oXref = aTextItems[0].obj;
}
sXRefID = oXref.XRefSrcText;
oDoc.Clear(0); // clear current selection
oTR = oDoc.TextSelection;
oXRef = oDoc.NewAnchoredFormattedXRef(sName, oTR.beg); // Insert a new xref object
oXRef.XRefSrcIsElem = false; // make it an unstructured xref (is default, leave out)
oXRef.XRefFile = oDoc.Name; // required also for 'in-document' xref?
oXRef.XRefSrcText = sXRefID;
oDoc.UpdateXRef(oDoc, oXref); // Establish the new xref.