Skip to main content
October 31, 2023
Answered

Identifying cross-references in textinsets through the entire book

  • October 31, 2023
  • 1 reply
  • 395 views

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. 

    This topic has been closed for replies.
    Correct answer frameexpert

    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

    1 reply

    frameexpert
    Community Expert
    Community Expert
    October 31, 2023

    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:

     

    • How do I get the path to a text inset? Its InsetFile property.
    • How do I open a text inset? Just like opening any other FrameMaker document.
    • How do I find markers in a FrameMaker document?
    • How do I find cross-references in a FrameMaker document?
    • How do I navigate all of the components in a book?

     

    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.

    frameexpert
    Community Expert
    frameexpertCommunity ExpertCorrect answer
    Community Expert
    November 1, 2023

    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

    November 7, 2023

    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.