Skip to main content
Participant
September 26, 2023
Question

Detect excluded book components on FM via scripting

  • September 26, 2023
  • 1 reply
  • 177 views

Hi, I am a beginner and I would like to write a script where excluded book components on FrameMaker can be automatically detected. However, I am stuck somehow even though I went through the entire pdf documentation several times. This is the code I was working on so far:

 

main();

function main() {

var book = app.ActiveBook;

if(!book.ObjectValid())
{
book = app.FirstOpenBook;
}

var bookComponentsPaths = []

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);
}
comp = comp.NextBookComponentInDFSOrder;


if (comp.ExcludeComponent = "Yes") {
alert("This file has a excluded component: " + comp.Name);
}
}
}

/*
if (bookComponentsPaths.indexOf(comp.ElementIsExcludedInContext) === -1)
{
alert("This component is excluded: " + comp.Name);
}

*/
}

 

 

I have tried with 'ExcludeComponent' and 'ElementIsExcludedInContext' and both did not work.

 

For testing, I also wrote a script going through the entire book and giving me the output of all components and the (apparently) excluded book component seems to be still detected by the script?? Is there something I might miss?

    This topic has been closed for replies.

    1 reply

    frameexpert
    Community Expert
    Community Expert
    September 26, 2023

    This:

    if (comp.ExcludeComponent = "Yes")

    should be this:

    if (comp.ExcludeBookComponent === 1)

    Participant
    September 27, 2023

    Hi frameexpert,

     

    Thank you for your quick response!

    But every time, I try this out, my FrameMaker always loops with the loading and does not really react until it crashes...

    My other scripts I wrote do not have this problem.

    Is there maybe another alternative?

    frameexpert
    Community Expert
    Community Expert
    September 27, 2023

    The crashing is not related to the original question. You should test my solution first so that this post can have an answer. Here is what you can do: open a book that has an excluded component. Select the component and run the code below. It should display 1 in the dialog box. Select a component that is not excluded and run the script again; it should display 0 in the dialog box. If this works, you can mark my answer as correct and then start a new post so we can address the crashing issue. Thanks!

    #target framemaker
    
    main ();
    
    function main () {
    
        var book, bookComp;
        
        book = app.ActiveBook;
        if (book.ObjectValid () === 1) {
            bookComp = book.FirstSelectedComponentInBook;
            if (bookComp.ObjectValid () === 1) {
                alert (bookComp.ExcludeBookComponent);
            }
        }
    }