Copy link to clipboard
Copied
Hi,
I am trying to write a script where all cross-references in general can be identified in textinsets within the entire book.
My approach is: first, identify all textinsets and second, identify all XRefs and MTexts in all textinsets through the entire book. I also intend to open the original files of the textinsets via scripting. However, my script does not work as planned, in particular, the insetDoc cannot be opened and also all cross-references outside the textinsets are mistakenly counted instead, so maybe I might miss something?
main();
function main(){
var bookComponentsPaths = []
var textInsetsPaths = []
var xRefPaths = []
var mTextPaths = []
var sourcePaths = []
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)
{
bookComponentsPaths.push(comp.Name);
var inset = doc.FirstTiInDoc;
while (inset.ObjectValid())
{
textInsetsPaths.push(doc.Name);
alert("File with Textinset: " + doc.Name);
sourcePaths.push(inset.TiFile);
alert("Original file is: " + inset.TiFile);
var insetDoc = inset.TiFile;
OpenFile(insetDoc);
if(insetDoc.ObjectValid() == true)
{
var xRef = insetDoc.FirstXRefInDoc;
while(xRef.ObjectValid())
{
xRefPaths.push(xRef.XRefFile);
xRef = xRef.NextXRefInDoc;
}
var mText = insetDoc.FirstMarkerInDoc;
while(mText.ObjectValid())
{
mTextPaths.push(mText.MarkerText);
mText = mText.NextMarkerInDoc;
}
}
insetDoc = insetDoc.NextTiInDoc;
}
}
else
{
alert("Error in running the script.");
return;
}
}
comp.ComponentIsSelected = false;
comp = comp.NextBookComponentInDFSOrder;
}
alert("Following " + textInsetsPaths.length
+ " textinsets were found in these files: "
+ textInsetsPaths
+ "\n\nThe textinsets originate from "
+ sourcePaths.length + " files: "
+ sourcePaths
+ "\n\nFollowing " + xRefPaths.length
+ " starting marks were found in the textinsets: "
+ xRefPaths
+ "\n\nIn total, " + mTextPaths.length
+ " target marks were found in the textinsets: "
+ mTextPaths);
}
Thank you in advance.
Here is an example of dividing your script into tasks, and then developing a function for each one:
https://community.adobe.com/t5/framemaker-discussions/table-formatting/m-p/14200965#M81613
Copy link to clipboard
Copied
Hi. These top-to-bottom scripts are hard to follow. More importantly, they are hard to develop, test, and troubleshoot. I suggest that you break this down into individual tasks:
Each task might represent a function or two in your script. And they may make up a separate post in the forum.
I can see several problems with your script, but I am hesitant to point them out because if your development process followed the task model that I have outlined, most of the problems would be easier to see. If I have more time later, I will help you organize your script better.
Copy link to clipboard
Copied
Here is an example of dividing your script into tasks, and then developing a function for each one:
https://community.adobe.com/t5/framemaker-discussions/table-formatting/m-p/14200965#M81613
Copy link to clipboard
Copied
Hi, thank you so much. I really appreciate your advice and I am trying to put this into practice. I will open a separate post then.