1 Reply Latest reply on Jun 8, 2017 1:08 PM by frameexpert

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

    varuns44789478 Level 1

      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;

          }

      }

        • 1. Re: How to check if a paragraph is/contains an anchored frame or not? if it is/does, apply/remove conditional tags on it?
          frameexpert Level 4

          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

          1 person found this helpful