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

How could I add Existing Variables into a Paragraph using ExtendScripts?

New Here ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Hi,

Based on a specific paragraph tag, I would like to add an existing variable (Name and Fmt) as part of the paragraph's text. I am able to add strings as part of paragraph texts at the moment.

I was looking up extend scripts to do this, however I am quite not sure how to add a variable. I could only find instances of updating variable values and so on.

Any help would be appreciated.

Giving a brief overview of my intention: (For example; Variable = "Part Number: 0x404"

                            var newpgf = doc.NewSeriesObject(Constants.FO_Pgf, pgf);

                            var attribute= doc.GetNamedObject(Constants.FO_VarFmt, "Variable");

           

                            var textLoc = new TextLoc();

                            textLoc.obj = newpgf;

                            textLoc.offset = -1;

                         

                                                               doc.AddText(textLoc, "( ");

                                                                         

Something like this:                            -> doc.AddText(textLoc, attribute.Fmt);       // Not Sure how to do this, possibly link the variable text range to this Text Location?

                                                               doc.AddText(textLoc, " )");               

Expected Paragraph:

                                             <Previous Para>

          new Para:                    (Part Number: 0x404 )

Thanks,
Sebin

TOPICS
Scripting

Views

318

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 , Mar 15, 2017 Mar 15, 2017

#target framemaker

var doc = app.ActiveDoc;

// Get the paragraph object where the cursor is.

var pgf = doc.TextSelection.beg.obj;

// Make a text loc object.

var textLoc = new TextLoc (pgf, 0);

// Add the open parens.

textLoc = doc.AddText (textLoc, "(");

// Add the variable.

doc.NewAnchoredFormattedVar ("Variable", textLoc);

// Add the trailing parens.

textLoc = new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET - 1);

textLoc = doc.AddText (textLoc, ")");

Make sure you test that your variable format exists (in my

...

Votes

Translate

Translate
Community Expert ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

#target framemaker

var doc = app.ActiveDoc;

// Get the paragraph object where the cursor is.

var pgf = doc.TextSelection.beg.obj;

// Make a text loc object.

var textLoc = new TextLoc (pgf, 0);

// Add the open parens.

textLoc = doc.AddText (textLoc, "(");

// Add the variable.

doc.NewAnchoredFormattedVar ("Variable", textLoc);

// Add the trailing parens.

textLoc = new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET - 1);

textLoc = doc.AddText (textLoc, ")");

Make sure you test that your variable format exists (in my example, the variable format name is "Variable"). Please let me know if you have any questions or comments. -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
New Here ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

LATEST

Thank you, Rick. It worked!

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