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
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.
...Copy link to clipboard
Copied
Is your text frame connected to other text frames or just a separate text frame?
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.
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
Copy link to clipboard
Copied
Ok thank you for you answer.It works fine.
Orveo