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

Cross-Reference creation

New Here ,
Jul 08, 2014 Jul 08, 2014

Copy link to clipboard

Copied

Hello to all!

I am new to this amazing world of Extendscript but I have been using Framemaker since version 5.5.

I am working on a kind of cross-reference manager and it works really nice. I can list all cross-references at book or document level, select the cross-reference to be shown in the current document and so on. I am using non-structured FM.

The problem I am facing is the creation of cross-reference itself.I know how to create a Cross-Ref Marker for the Xref, but I don´t know how to insert the Xref into the content. I tried with NewAnchoredFormattedObject function with objType, format and textLoc parameters. Also there´s the XRefSrcText property (string containg unique ID:pgf_tag:text).

The question is: Should I use the same string (the content of XRefSrcText) as text for the Cross-Ref type Marker? Or just the pgf text that contains the Cross-Ref?

I have found several examples using Framescript but I am unable to replicate the code using ES.

Thanks for reading me. I will appreciate any help on this.

Regards

TOPICS
Scripting

Views

1.1K

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

Advocate , Jul 15, 2014 Jul 15, 2014

Hi,

Your code does work, but you forgot to update the cross-references in your document. To do this in the code, add the following line to the end of the XRef insertion code snippet:

doc.UpdateXRef ( doc, newcrossref );

Ciao

Jang

Votes

Translate

Translate
Advocate ,
Jul 08, 2014 Jul 08, 2014

Copy link to clipboard

Copied

Use the NewAnchoredFormattedXRef method instead. It works in my script (which creates XRefs for structured FM documents).

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 ,
Jul 08, 2014 Jul 08, 2014

Copy link to clipboard

Copied

Hi Jang:

First of all let me thank you for all your documentation regarding ES and Framescript, I have learn a lot with all your tips.

How can I connect or link the Cross-Ref Marker to the Xref? Using the XRefSrcText property perhaps? And also, do I need to use the string with unique ID:pgf_tag:text or just the pgf text that contains the marker.

May I ask you to publish the code for this method?

Thanks

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 ,
Jul 08, 2014 Jul 08, 2014

Copy link to clipboard

Copied

Not right now. The code I have is for structured FM documents and would need some changes to make it work for unstructured documents, and I am on holiday in the Dutch Carribean. Possibly next week, if I remember to do it. There are a couple of things you need to figure out about the XRefs in FM. If you cannot wait until next week, use this method to learn about XRefs:

1. Create an XRef using FM's own method

2. Select the XRef in your document

3. Create a script that allows you to investigate the oDoc.TextSelection that contains the XRef marker - use the Data Browser in the ESTK for this.

4. Make small changes to the XRef marker from your test script and see what happens to the XRef in FM

Good luck

Jang

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 ,
Jul 15, 2014 Jul 15, 2014

Copy link to clipboard

Copied

Hi again Jang:

I have been trying to create the XREF following your suggestions:

  1. First I created a XREF using the FM procedure. Then I created a code to get the info from Data Browser in the ESTK.
  2. Then I created a XREF using my own code: FM recognizes the XREF (as you can see on the right image) but I cannot get any cross-ref on the content.

XREF comparison.jpg

Here is the code for the Cross-ref marker target creation:

var doc = app.ActiveDoc;

var flow = doc.MainFlowInDoc;

var pgf = doc.TextSelection.beg.obj

var tLoc, marker, markerType;

tLoc = new TextLoc(pgf, 0);

marker = doc.NewAnchoredObject(Constants.FO_Marker, tLoc);

markerType = doc.GetNamedObject(Constants.FO_MarkerType, "Cross-Ref");

marker.MarkerTypeId = markerType;

marker.MarkerText = "10978: Heading1: PREAMBLE";

Here is the code I am using to create the XREF:

var doc = app.ActiveDoc;

var flow = doc.MainFlowInDoc;

var pgf = doc.TextSelection.beg.obj;

var oTLoc1=new TextLoc (pgf, 0);

var format="Page";

var newcrossref=doc.NewAnchoredFormattedXRef(format, oTLoc1);

newcrossref.XRefFmt.Name=format;

newcrossref.XRefSrcText= "10978: Heading1: PREAMBLE";

I have tried with tons of modifications but without success.

I hope you can help me!

Regards

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 ,
Jul 15, 2014 Jul 15, 2014

Copy link to clipboard

Copied

Hi,

Your code does work, but you forgot to update the cross-references in your document. To do this in the code, add the following line to the end of the XRef insertion code snippet:

doc.UpdateXRef ( doc, newcrossref );

Ciao

Jang

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 ,
Jul 16, 2014 Jul 16, 2014

Copy link to clipboard

Copied

Thanks a lot Jang!!!!

Yes it works with all cross-references in the same document. If you create cross-references to others files you will need to specify the XRefFile parameter and use the UpdateXRefs method instead of UpdateXRef.


Again, thanks for your help

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 ,
Jul 05, 2022 Jul 05, 2022

Copy link to clipboard

Copied

LATEST

Hi, 

I need a similar help. I am trying to generate the cross-reference for the registers in the structured FM file using javascript. all the resgisters name get imported but for some the complete name is not hit and recorded.

 

for example,

If the register name is SCB_INT and second register name is SCB_INT1 then only SCB_INT appears and not the 2nd one.

 

main();

var docTable, doc;

function main()
{
docTable = app.FirstOpenDoc;
if(docTable.ObjectValid() == true)
{
doc = docTable.NextOpenDocInSession;
}
else
{
alert ("Input Files Missing", "Error", 1);
}
if(doc.ObjectValid() == true)
{
FindAllRegisters(doc);
}
else
{
alert ("Input Files Missing", "Error", 1);
}
}


function FindAllRegisters(doc)
{
// Get the first paragraph
var pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

// find the registers
while(pgf.ObjectValid())
{
if(pgf.Name == "Reg Heading")
{
var textItems = pgf.GetText(-1);
var counter;
for(counter = 0 ; counter < textItems.len; counter++)
{
var textItem = textItems[counter];
if(textItem.sdata != "")
{
// Creating Anchor point
var tLoc = new TextLoc(pgf, 1);

// Create new Anchored object
var marker = doc.NewAnchoredObject(Constants.FO_Marker, tLoc);

if(marker.ObjectValid() != true)
{
DebugPrintf("Failed to create NewAnchoredObject for ->" + textItem.sdata);
}
else
{
var markerType = doc.GetNamedObject(Constants.FO_MarkerType, "Cross-Ref");
if(markerType.ObjectValid() == true)
{
marker.MarkerTypeId = markerType;
marker.MarkerText = textItem.sdata;

doc.UpdateXRef(doc, marker);
CreateCrossRef(textItem.sdata);
break;
}
}
}
}
}
pgf = pgf.NextPgfInFlow;
}
var cmd = app.GetNamedCommand ("Update");
Fcodes ([cmd.Fcode]);
}

function CreateCrossRef(registerName)
{
// Start point in the document
var docStart = docTable.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
var tLoc = new TextLoc (docStart, 0);

var foundText = FindTextRange(registerName, tLoc);

while(foundText.beg.obj.ObjectValid())
{
// Remove found register
RemoveString(docTable, foundText);

var oTLoc = new TextLoc(foundText.beg.obj, foundText.beg.offset);

var format="Page";
var newcrossref = docTable.NewAnchoredFormattedXRef(format, oTLoc);
if(newcrossref.ObjectValid() != true)
{
DebugPrintf("Failed to create NewAnchoredFormattedXRef object !!");
}
else
{
newcrossref.XRefFmt.Name=format;
newcrossref.XRefFmt.Fmt = "<Hypertext><$paratext>";
newcrossref.XRefFile = doc.Name;
newcrossref.XRefSrcText= registerName;
}

docTable.UpdateXRef(docTable, newcrossref);
foundText = FindTextRange(registerName, tLoc);
}
}

function FindTextRange(text, tLoc)
{
// Define search parameter
findParams = AllocatePropVals(2);
findParams[0].propIdent.num = Constants.FS_FindText ;
findParams[0].propVal.valType = Constants.FT_String;
findParams[0].propVal.sval = text;

findParams[1].propIdent.num = Constants.FS_FindCustomizationFlags;
findParams[1].propVal.valType = Constants.FT_String;
findParams[1].propVal.ival = Constants.FF_FIND_WHOLE_WORD|Constants.FF_FIND_USE_WILDCARDS;

// Search text
return docTable.Find(tLoc, findParams);
}


function RemoveString(document, textRange)
{
document.TextSelection = textRange;
document.Clear(0);
}

function DebugPrintf(Msg)
{
$.writeln(Msg);
}

 

 

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