Highlighted

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

Community Beginner ,
Jan 17, 2018

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

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

TOPICS
Scripting

Views

231

Likes

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

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

Community Beginner ,
Jan 17, 2018

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

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

TOPICS
Scripting

Views

232

Likes

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
Jan 17, 2018 0
Adobe Community Professional ,
Jan 17, 2018

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jan 17, 2018 0
Community Beginner ,
Jan 18, 2018

Copy link to clipboard

Copied

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

this textframe is like a title.

Likes

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
Reply
Loading...
Jan 18, 2018 0
Adobe Community Professional ,
Jan 18, 2018

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jan 18, 2018 0
Community Beginner ,
Jan 23, 2018

Copy link to clipboard

Copied

Ok thank you for you answer.It works fine.

Orveo

Likes

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
Reply
Loading...
Jan 23, 2018 0