• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Detect excluded book components on FM via scripting

New Here ,
Sep 26, 2023 Sep 26, 2023

Copy link to clipboard

Copied

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?

Views

73

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2023 Sep 26, 2023

Copy link to clipboard

Copied

This:

if (comp.ExcludeComponent = "Yes")

should be this:

if (comp.ExcludeBookComponent === 1)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 27, 2023 Sep 27, 2023

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 27, 2023 Sep 27, 2023

Copy link to clipboard

Copied

LATEST

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);
        }
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines