Copy link to clipboard
Copied
Hi,
I am facing problem in inserting Xref in the document that Xref is linked to the Figure in different document. I am not getting the logic how this can be established using Extend Script. Please guide me how this can be done. If possible, please share the example Script.
Thanks & Regards,
Lohithkumar
1 Correct answer
I don't have code to do this, but can give an an outline of what I believe is required, This is untested and might be incomplete:
- At the start of your Figure paragraph, insert a marker by calling Doc.NewAnchoredMarker()
- Get the default properties used to create the new marker by calling Marker.GetProps()
- Change the returned MarkerTypeId property to the "XRef" marker type:
use Doc.GetNamedMarkerType() to fetch the marker type id - Change the returned MarkerText property to a unique string,
- Change other
Copy link to clipboard
Copied
I don't have code to do this, but can give an an outline of what I believe is required, This is untested and might be incomplete:
- At the start of your Figure paragraph, insert a marker by calling Doc.NewAnchoredMarker()
- Get the default properties used to create the new marker by calling Marker.GetProps()
- Change the returned MarkerTypeId property to the "XRef" marker type:
use Doc.GetNamedMarkerType() to fetch the marker type id - Change the returned MarkerText property to a unique string,
- Change other returned properties as required
- Update the properties of the new marker by calling Marker.SetProps()
- At the location for your cross reference, insert an XRef by calling Doc.NewAnchoredFormattedXRef()
- Get the default properties used to create the new cross reference by calling XRef.GetProps()
- Change the returnedXRefFile property to the file containing the marker
- Change the returnedXRefSrcText property to the unique string in the marker
- Change the returnedXRefFormat poroperty as required:
use Doc.GetNamedXRefFmt() to fetch the format id - Change other returned properties as required
- Update the properties of the new cross reference by calling XRef.SetProps()
- Update the cross reference cy calling Doc.UpdateXRef.
I'm sorry, but I don't have the bendwidth rght now to give further help.
Copy link to clipboard
Copied
Thanks you very much Mike for providing complete logic.
I will work on that to get the results .
Thanks & Regards,
Lohithkumar
Copy link to clipboard
Copied
Hi Lohithkumar,
Mike's summary is pretty good. Here is some almost-complete sample code that inserts an unstructured xref to a different file. The xref is inserted at the current insertion point in the source doc, and targets the paragraph with the insertion point in the target doc. This may not be exactly how you want to locate the new items but it is the simplest way to demonstrate how its done.
Russ
function insertXRef()
{
var sourceDoc =
/* some code to get the doc in which to insert the xref */
var targetDoc =
/* some code to get the doc that the xref will target */
//Insert a new marker object at the current insertion point
var marker = targetDoc.NewAnchoredMarker(targetDoc.TextSelection.beg);
//Make it a Cross-Ref marker, required for xrefs to target
marker.MarkerTypeId = targetDoc.GetNamedMarkerType ("Cross-Ref");
//Add some marker text. This needs to be unique among all
//Cross-Ref markers in the doc
marker.MarkerText = "xref_target_id";
//Insert a new xref object at the current insertion point in the source doc.
//Note that "Para_Text" is the xref format... you would need to use a format
//from your template.
var xref = sourceDoc.NewAnchoredFormattedXRef("Para_Text", sourceDoc.TextSelection.beg);
//Set the properties required to make it an unstructured xref to the
//new marker in the other doc.
xref.XRefSrcIsElem = false;
xref.XRefFile = targetDoc.Name;
xref.XRefSrcText = marker.MarkerText;
//Update the new xref.
sourceDoc.UpdateXRef(targetDoc, xref);
}

