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

How to check if a paragraph is/contains an anchored frame or not? if it is/does, apply/remove conditional tags on it?

New Here ,
Jun 08, 2017 Jun 08, 2017

Copy link to clipboard

Copied

Hi, I am new to Extendscript and Framemaker. I am trying to cycle through a book and find which paragraphs are/contain anchored frames. If they contain an anchored frame, I want to be able to select the paragraph and apply/remove conditional tags on the paragraph.

This is what I have so far:

//code to Show All conditions including hidden ones in book.

//take the object of the active book

var openedBook = app.ActiveBook;

//function call - defiend below

openBookFiles(openedBook);

function openBookFiles(openedBook)

{

    var bookChapter = openedBook.FirstComponentInBook;

    var counter = 0;

    if(bookChapter.ObjectValid())

    {

        var chapterId = bookChapter.id;

        while (chapterId)

        {

            var chapterName = bookChapter.Name;

            chapterId = openFile(chapterName);

            var msg = "Opened Chapter " + chapterName + "Component #"+ counter + "\n\n";

            alert(msg);

            counter++;

            bookChapter.ComponentIsSelected = true;

            chapterId.ShowAll = 1;

            bookChapter = bookChapter.NextComponentInBook;

            chapterId = bookChapter.id;

        }

    }

//code to find all paragraphs in book, check to see if they are/contain anchored frames or not.

    var mainflow = doc.MainFlowInDoc;

    var tframe = mainflow.FirstTextFrameInFlow;

    var pgf = tframe.FirstPgf;

    while (pgf.ObjectValid())

    {

        //find out if the paragraph is/contains an anchored frame

        //if it does, deslect/select a condition tag applied on the paragraph.

        pgf = pgf.NextPgfInFlow;

    }

}

TOPICS
Scripting

Views

354

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

correct answers 1 Correct answer

Community Expert , Jun 08, 2017 Jun 08, 2017

I like to isolate tasks into functions:

function hasAnchoredFrame(textObj) {

    var textList;

    textList = textObj.GetText (Constants.FTI_FrameAnchor);

    if (textList.length) {

        return true;

    }

    else {

        return false;

    }

}

Then you can call this in your code:

if (hasAnchoredFrame (pgf) === true) {

    // Do something with the paragraph.

}

Try to get in the habit of isolating tasks into functions and then assembling them into finished scripts. This facilitates testing, troubleshooting

...

Votes

Translate

Translate
Community Expert ,
Jun 08, 2017 Jun 08, 2017

Copy link to clipboard

Copied

LATEST

I like to isolate tasks into functions:

function hasAnchoredFrame(textObj) {

    var textList;

    textList = textObj.GetText (Constants.FTI_FrameAnchor);

    if (textList.length) {

        return true;

    }

    else {

        return false;

    }

}

Then you can call this in your code:

if (hasAnchoredFrame (pgf) === true) {

    // Do something with the paragraph.

}

Try to get in the habit of isolating tasks into functions and then assembling them into finished scripts. This facilitates testing, troubleshooting, and reuse. When you string all of your code together linearly, it causes problems with maintenance and scaling.

-Rick

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