Skip to main content
Inspiring
January 17, 2018
Answered

How to clear and set a new string to a textframe ?

  • January 17, 2018
  • 1 reply
  • 540 views

Hello forum.

A simple question that seems to be easy .

How to clear  a textframe and set à new string in it.

assuming this code :

if (textFrame.ObjectValid()) {

      if (textFrame.constructor.name === "TextFrame") {

         // how to clear the text inside the textframe

          // how to set the new string " new text in the textframe"

      }

    }

this text frame in on a reference page inside an unanchoredframe but i know how to get there.

thank you for your help

Orveo

This topic has been closed for replies.
Correct answer frameexpert

This will work with a selected text frame:

#target framemaker

var doc = app.ActiveDoc;

var textFrame = doc.FirstSelectedGraphicInDoc;

// Delete the first paragraph in the text frame.

textFrame.FirstPgf.Delete ();

// Add the new text.

var textLoc = new TextLoc (textFrame.FirstPgf, 0);

doc.AddText (textLoc, "The new text I want to add.");

Since you already have a TextFrame object (the textFrame variable) in your code, just use lines 5-9. Note that on line 9, you do need a Doc object for the AddText method.

Rick

1 reply

frameexpert
Community Expert
Community Expert
January 17, 2018

Is your text frame connected to other text frames or just a separate text frame?

www.frameexpert.com
Inspiring
January 18, 2018

in the unanchored frame on the reference page there (is) are graphic frame(s) and only one textframe.

this textframe is like a title.

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
January 18, 2018

This will work with a selected text frame:

#target framemaker

var doc = app.ActiveDoc;

var textFrame = doc.FirstSelectedGraphicInDoc;

// Delete the first paragraph in the text frame.

textFrame.FirstPgf.Delete ();

// Add the new text.

var textLoc = new TextLoc (textFrame.FirstPgf, 0);

doc.AddText (textLoc, "The new text I want to add.");

Since you already have a TextFrame object (the textFrame variable) in your code, just use lines 5-9. Note that on line 9, you do need a Doc object for the AddText method.

Rick

www.frameexpert.com