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

Script to add markers to text by paragraph format

New Here ,
Jul 31, 2012 Jul 31, 2012

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

3.5K

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 , Aug 05, 2012 Aug 05, 2012

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.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", getTe

...

Votes

Translate

Translate
Engaged ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

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;

          continue

     }

     //do code for setting markers

     pgf = pgf.NextParagraphInDoc;

}

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 ,
Aug 02, 2012 Aug 02, 2012

Copy link to clipboard

Copied

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!

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 ,
Aug 05, 2012 Aug 05, 2012

Copy link to clipboard

Copied

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;

    }

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 ,
Aug 05, 2012 Aug 05, 2012

Copy link to clipboard

Copied

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.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

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 ,
Aug 05, 2012 Aug 05, 2012

Copy link to clipboard

Copied

LATEST

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

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