5 Replies Latest reply on Aug 5, 2012 5:21 PM by mrsjackharkness

    Script to add markers to text by paragraph format


      With previous versions of Framemaker, I had a FrameScript which would loop through my document and add a marker to text based on the paragraph format applied. The marker text would be the selected paragraph.


      I am now trying to recreate this in Extendscript for use in Framemaker 10 and am completely stumped.


      I have no doubt that my script (copied below) is completely off-track, but I wondered if anybody would be able to help point me in the direction of my many mistakes.


      Basically, I want the script to find all paragraphs with the "*Part no." format applied, make that text the text range and then apply a marker to that range. A bit of research has shown that I probably need to create a list of paragraph formats, but I believe that I have far more problems than just that.


      var pgfFmt1 = flow.GetNamedPgfFmt (*Part no.);

      while (pgfFmt1.ObjectValid())  


          function createMarker (doc, pgf, offset, type, text)    {

              var tRange, marker;

              tRange = pgfFmt1.TextRange;

              marker = doc.NewAnchoredObject(Constants.FO_Marker, tRange);

              marker.MarkerType = type;

              marker.MarkerText = text;

              return 1;


      createMarker (doc, pgf, 0, "Index", 0);


      Many thanks in advance to anyone who is able to offer me some pointers!

        • 1. Re: Script to add markers to text by paragraph format
          Wiedenmaier Level 3

          If you have an working FrameScript you only have to bring that syntax to ExtendScript and particular a little bit more ;-)

          But there is your algorithm, to find paragraphs... and there are hints how to use the FrameMaker object model


          Searching for paragraph in a document works like this pseudo code:


          var pgf = app.ActiveDoc.FirstParagraphInDoc;

          while (pgf.ObjectIsValid()


               if (pgf.Name != 'Partno')


                    pgf = pgf.NextParagraphInDoc;




               //do code for setting markers


               pgf = pgf.NextParagraphInDoc;


          • 2. Re: Script to add markers to text by paragraph format
            mrsjackharkness Level 1

            Hi! Thanks for your assistance, but I decided to bite the bullet and really delve into Javascript/Extendscript and did finally manage to come up with a working script.


            Thanks again!

            • 3. Re: Script to add markers to text by paragraph format
              mrsjackharkness Level 1

              Well, it seems that my script is only 95% there. While my script finds the target paragraphs and adds a marker, only the first word of each paragraph is selected as the marker text. I really need the script to select the whole paragraph as the marker text. I have tried many combinations, but cannot seem to get the right outcome. Could anybody please point me in the right direction? Script is copied below. Many thanks!


              var doc = app.ActiveDoc;

              var flow = doc.MainFlowInDoc;

              var tframe = flow.FirstTextFrameInFlow;

              var pgf = tframe.FirstPgf;

              var target1 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Part no.");

              var target2 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Parent Bold");

              var target3 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Child");

              var target4 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Child indent");

              var target5 = doc.GetNamedObject(Constants.FO_PgfFmt, "*Child indent 2");

              while (pgf.ObjectValid())   {

              if (pgf.Name == target1.Name)   {

                  createMarker (doc, pgf, 0, "Index", "");


              else if (pgf.Name == target2.Name)  {

                  createMarker (doc, pgf, 0, "Subject", "");


              else if (pgf.Name == target3.Name)  {

                  createMarker (doc, pgf, 0, "Subject", "");


              else if (pgf.Name == target4.Name)  {

                  createMarker (doc, pgf, 0, "Subject", "");


              else if (pgf.Name == target5.Name)  {

                  createMarker (doc, pgf, 0, "Subject", "");


              pgf = pgf.NextPgfInDoc;


              function createMarker(doc, pgf, offset, type, text) {

                  var tLoc = new TextLoc(pgf, offset);

                  var marker = doc.NewAnchoredObject(Constants.FO_Marker, tLoc);

                  var markerType = doc.GetNamedObject(Constants.FO_MarkerType, type);

                  marker.MarkerTypeId = markerType;

                  marker.MarkerText = text;

                  return 1;


              • 4. Re: Script to add markers to text by paragraph format
                frameexpert Level 4

                You can use the following function to get the text from a FrameMaker paragraph.


                function getText(textObj) {


                  var objText = "";

                  // Get a list of strings from the object.

                  var textItems = textObj.GetText(Constants.FTI_String);

                  // Concatenate the strings.

                  for (var i = 0; i < textItems.len; i += 1) {

                    objText += (textItems[i].sdata);



                  return objText;



                Once you add it to your script, you can modify each call to createMarker to something like this:


                createMarker (doc, pgf, 0, "Subject", getText(pgf));


                --Rick Quatro

                • 5. Re: Script to add markers to text by paragraph format
                  mrsjackharkness Level 1

                  Thanks very much! The script now does exactly what I need it to!