Copy link to clipboard
Copied
Hi everybody,
I've spent a ton of time trying to understand how textDocument works, but I just can't seem to wrap my mind around it.
In the script I'm working on, I take text entered into an edittext box, then split it up by word, entering it into an array. I add it to the comp, one word per layer. I'd like to be able to pick the font size and color before it creates these layers.
Here is the function that responds to a button click:
buttonCreate.onClick = function () {
var stringArray = myEditText.text.split(" ");
var stringArrayNumItems = stringArray.length;
//Loop through stringArray words
for(i=0;i<stringArrayNumItems;i++) {
curComp.layers.addText(stringArray);
}
}
So, I know I need to put that line that includes .addText in it into a variable. I just don't know how to go through and edit its properties.
Thanks!
-Justin
var curComp = app.project.activeItem; //Assumes the activeItem is a CompItem
if(curComp instanceof CompItem){//Makes sure that it is a CompItem
var myTextLayer = curComp.layers.addText("Initial text layer creation");//Creates the text layer
var textProp = myTextLayer.property("Source Text");//Assigns the text layer source text property to a variable
var textDocument = textProp.value;//Gets the source text property value
//Begin assigning each text layer related attribute to the textDocument v
...Copy link to clipboard
Copied
var curComp = app.project.activeItem; //Assumes the activeItem is a CompItem
if(curComp instanceof CompItem){//Makes sure that it is a CompItem
var myTextLayer = curComp.layers.addText("Initial text layer creation");//Creates the text layer
var textProp = myTextLayer.property("Source Text");//Assigns the text layer source text property to a variable
var textDocument = textProp.value;//Gets the source text property value
//Begin assigning each text layer related attribute to the textDocument variable
myString = "Happy holidays!";
textDocument.resetCharStyle();
textDocument.fontSize = 60;
textDocument.fillColor = [1, 0, 0];
textDocument.strokeColor = [0, 1, 0];
textDocument.strokeWidth = 2;
textDocument.font = "TimesNewRomanPSMT";
textDocument.strokeOverFill = true;
textDocument.applyStroke = true;
textDocument.applyFill = true;
textDocument.text = myString;
textDocument.justification = ParagraphJustification.CENTER_JUSTIFY;
textDocument.tracking = 50;
//Apply all that data to your already created textLayer source text property
textProp.setValue(textDocument);
}
Copy link to clipboard
Copied
Thank you so much. This was the breakdown I was looking for!!