Skip to main content
Participant
Sep 26, 2023 10:09 AM UTC
Question

Detect excluded book components on FM via scripting

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 is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    frameexpert
    Community Expert
    Community Expert
    Sep 26, 2023 11:20 AM UTC

    This:

    if (comp.ExcludeComponent = "Yes")

    should be this:

    if (comp.ExcludeBookComponent === 1)

    Translate
    www.frameexpert.com
    Participant
    Sep 27, 2023 7:26 AM UTC

    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?

    Translate
    frameexpert
    Community Expert
    Community Expert
    Sep 27, 2023 11:33 AM UTC

    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);
            }
        }
    }
    Translate
    www.frameexpert.com