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

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

Community Beginner ,
Jan 17, 2018 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

TOPICS
Scripting

Views

391

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 , Jan 18, 2018 Jan 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.

...

Votes

Translate

Translate
Community Expert ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

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

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 Beginner ,
Jan 18, 2018 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.

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 ,
Jan 18, 2018 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

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 Beginner ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

LATEST

Ok thank you for you answer.It works fine.

Orveo

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