Jump to orphaned target marks (MText) via scripting
Hi,
I am currently working on a script for FrameMaker which should directly jump to the orphaned target markers (MText) inside the book. To identify them in the first place, I have already written a code where I collect all cross-references (mainly the ID numbers), both source markers (XRef) and target markers, to match them. This works for me so far. However, I am a bit stuck with the part where the according book components of the orphaned target markers should be directly accessed. I was thinking of running through the entire book again while trying to match with the ID numbers of the target markers but since I collected them all in an array, this does not work properly. Maybe my approach is not that elegant.
main();
function main()
{
var numXRefTextPaths = []
var numMTextPaths = []
var book = app.ActiveBook;
if(!book.ObjectValid())
{
book = app.FirstOpenBook;
}
var comp = book.FirstComponentInBook;
while(comp.ObjectValid())
{
comp.ComponentIsSelected = true;
var compType = comp.ComponentType;
if(compType == Constants.FV_BK_FILE)
{
var doc = OpenFile(comp.Name);
if(doc.ObjectValid() == true)
{
crXRefText = doc.FirstXRefInDoc;
while(crXRefText.ObjectValid())
{
var longXRefText = crXRefText.XRefSrcText.toString();
var id_number = longXRefText.substr(0, 5);
//alert("CR-XRef: " + id_number);
numXRefTextPaths.push(id_number);
crXRefText = crXRefText.NextXRefInDoc;
}
crMText = doc.FirstMarkerInDoc;
while(crMText.ObjectValid())
{
if (crMText.MarkerText.match(/^[0-9]{5}/))
{
var longMText = crMText.MarkerText.toString();
var cr_number = longMText.substr(0, 5);
//alert("CR-MText: " + cr_number);
numMTextPaths.push(cr_number);
}
crMText = crMText.NextMarkerInDoc;
}
}
else
{
alert("Book cannot be found.\nRun the script again.");
return;
}
}
comp.ComponentIsSelected = false;
comp = comp.NextBookComponentInDFSOrder;
}
alert("Following cross-references were found:\n\n"
+ "\n\nXRefs ID: " + numXRefTextPaths
+ "\n\nMText ID: "+ numMTextPaths
);
function getOne(arr1, arr2)
{
var uniqueOne = [];
var matches = false;
for ( var i = 0; i < arr1.length; i++ )
{
matches = false;
for ( var j = 0; j < arr2.length; j++ )
{
if (arr1[i] === arr2[j]) matches = true;
}
if(!matches) uniqueOne.push(arr1[i]);
}
return uniqueOne;
}
alert("Orphaned target marks: " + getOne(numMTextPaths, numXRefTextPaths));
var comp = book.FirstComponentInBook;
while(comp.ObjectValid())
{
comp.ComponentIsSelected = true;
var compType = comp.ComponentType;
if(compType == Constants.FV_BK_FILE)
{
var doc = OpenFile(comp.Name);
if(doc.ObjectValid() == true)
{
var test = getOne(numMTextPaths, numXRefTextPaths);
jumpMText = doc.FirstMarkerInDoc;
while(jumpMText.ObjectValid())
{
if (jumpMText.MarkerText.match(test))
{
alert("Orphaned target marks: " + jumpMText.MarkerText);
}
jumpMText = jumpMText.NextMarkerInDoc;
}
}
else
{
alert("Book cannot be found.\nRun the script again.");
return;
}
}
comp.ComponentIsSelected = false;
comp = comp.NextBookComponentInDFSOrder;
}
}Thank you in advance.
