Skip to main content
DuanesSearchForKnowledge
Inspiring
March 20, 2013
Answered

adding text to a text frame?

  • March 20, 2013
  • 1 reply
  • 1578 views

Okay, I have yet another question. I can see the text in a text frame with a script like this,

var doc = app.activeDocument;

var myTextFrames = doc.textFrames[0];

var myTF_Content = myTextFrames.contents; // this will return the string inside the text frame

alert(myTF_Content);

but how do I add some text to the beginning of that text?

lets say that this is my textFrame[0] = "this is a simple test string"

what is the proper way to add text like the number one and a period to the beginning?

Any help would be appreciated,

Duane

This topic has been closed for replies.
Correct answer CarlosCanto

myTextFrames.contents = "1. " + myTextFrames.contents;

1 reply

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
March 20, 2013

myTextFrames.contents = "1. " + myTextFrames.contents;

DuanesSearchForKnowledge
Inspiring
March 22, 2013

Thanks Carlos, I was able to replace t the carriage return with a $ sign on all my text frames that had stacked text. The carriage return was messing up my script to split up stacked text.

var doc = app.activeDocument.activeLayer;

var myTextFrames = doc.textFrames;

    for (i = 0; i < myTextFrames.length; i++) {

        myTF_ByI = myTextFrames;

        myFirstChar = myTF_ByI.contents[0];

            if(myFirstChar == "\r") {

            myTF_ByI.contents = "$" + myTF_ByI.contents;

            }

    }

CarlosCanto
Community Expert
Community Expert
March 22, 2013

you're welcome