TextDocument object

new TextDocument(docText)
app.project.item(index).layer(index).property("Source Text").value

The TextDocument object stores a value for a TextLayer's Source Text property. Create it with the constructor, passing the string to be encapsulated.

Examples:

This sets a value of some source text and displays an alert showing the new value:

var myTextDocument = new TextDo cument("Happy Cake");
myTextLayer.property("Source Text").setValue(myTextDocument);
alert(myTextLayer.property("Source Text").value);

This sets keyframe values for text that show different words over time:

var textProp = myTextLayer.property("Source Text");
textProp.setValueAtTime(0, new TextDocument("Happy"));
textProp.setValueAtTime(.33, new TextDocument("cake"));
textProp.setValueAtTime(.66, new TextDocument("is"));
textProp.setValueAtTime(1, new TextDocument("yummy!"));

This sets various character and paragraph settings for some text:

var textProp = myTextLayer.property("Source Text");
var textDocument = textProp.value;
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;
textProp.setValue(textDocument);

Attribute List

Attribute Reference Description
text “TextDocument text attribute” on page 187 The text layer’s Source Text value.
font “TextDocument font attribute” on page 184 The text layer’s font specified by its PostScriptname.
fontSize “TextDocument fontSize attribute” on page 185 The text layer’s font size in pixels.
applyFill “TextDocument applyFill attribute” on page 183 When true, the text layer shows a fill.
applyStroke “TextDocument applyStroke attribute” on page^183 When true, the text layer shows a stroke.
fillColor “TextDocument fillColor attribute” on page 184 The text layer’s fill color.
strokeColor “TextDocument strokeColor attribute” on page 186 The text layer’s stroke color.
strokeOverFill “TextDocument strokeOverFill attribute” on page 186 Indicates the rendering order for the fill and stroke of a text layer.
strokeWidth “TextDocument strokeWidth attribute” on page 186 The text layer’s stroke thickness.
justification “TextDocument justification attribute” on page 185 The paragraph justification for the text layer.
tracking “TextDocument tracking attribute” on page 187 The text layer’s spacing between characters.
pointText “TextDocument pointText attribute” on page 185 When true, the text layer is point (unbounded) text.
boxText “TextDocument boxText attribute” on page 184 When true, the text layer is paragraph (bounded) text.
boxTextSize “TextDocument boxTextSize attribute” on page 184 For box text, the pixel dimensions for the text bounds.

Method List

Method Reference Description
resetCharStyle() “TextDocument resetCharStyle() method” on page 185 Restores the default character settings in the Character panel.
resetParagraphStyle() “TextDocument resetParagraphStyle() method” on page 186 Restores the default paragraph settings in the Paragraph panel.

applyFill attribute

textDocument.applyFill

When true, the text layer shows a fill. Access the fillColor attribute for the actual color. When false, only a

stroke is shown.

Type: Boolean read/write.


applyStroke attribute

textDocument.applyStroke

When true, the text layer shows a stroke. Access the strokeColor attribute for the actual color and strokeWidth

for its thickness. When false, only a fill is shown.

Type: Boolean read/write.


boxText attribute

textDocument.boxText

True if a text layer is a layer of paragraph (bounded) text; otherwise false.

Type: Boolean *read-only*


boxTextSize attribute

textDocument.boxTextSize

The size of a paragraph (box) text layer as a [width, height] array of pixel dimensions.

Type: Array of two integers (minimum value of 1); read/write.


fillColor attribute

textDocument.fillColor

The text layer’s fill color, as an array of [r, g, b] floating-point values. For example, in an 8-bpc project, a red

value of 255 would be 1.0, and in a 32-bpc project, an overbright blue value can be something like 3.2.

NOTE: If the text layer has different fill color settings for each character, this attribute returns the setting for the

first character. Also, if you change the value, it resets all characters in the text layer to the specified setting.

Type: Array [r, g, b] of floating-point values; read/write.


font attribute

textDocument.font

The text layer’s font specified by its PostScript name.

NOTE: If the text layer has different font settings for each character, this attribute returns the setting for the first

character. Also, if you change the value, it resets all characters in the text layer to the specified setting.

Type: String; read/write.

185

After Effects scripting reference TextDocument object

fontSize attribute

textDocument.fontSize

The text layer’s font size in pixels.

NOTE: If the text layer has different font size settings for each character, this attribute returns the setting for the

first character. Also, if you change the value, it resets all characters in the text layer to the specified setting.

Type: Floating-point value (0.1 to 1296, inclusive); read/write.


justification attribute

textDocument.justification

The paragraph justification for the text layer.

Type: A ParagraphJustification enumerated value; read-only One of:

ParagraphJustification.LEFT_JUSTIFY
ParagraphJustification.RIGHT_JUSTIFY
ParagraphJustification.CENTER_JUSTIFY
ParagraphJustification.FULL_JUSTIFY_LASTLINE_LEFT
ParagraphJustification.FULL_JUSTIFY_LASTLINE_RIGHT
ParagraphJustification.FULL_JUSTIFY_LASTLINE_CENTER
ParagraphJustification.FULL_JUSTIFY_LASTLINE_FULL

pointText attribute

textDocument.pointText

True if a text layer is a layer of point (unbounded) text; otherwise false.

Type: Boolean read-only


resetCharStyle() method

textDocument.resetCharStyle()

Restores the default text character characteristics in the Character panel.

Parameters: None.

186

After Effects scripting reference TextDocument object

Returns: Nothing.


resetParagraphStyle() method

textDocument.resetParagraphStyle()

Restores the default text paragraph characteristics in the Paragraph panel.

Parameters: None.

Returns: Nothing.


strokeColor attribute

textDocument.strokeColor

The text layer’s stroke color, as an array of [r, g, b] floating-point values. For example, in an 8-bpc project, a

red value of 255 would be 1.0, and in a 32-bpc project, an overbright blue value can be something like 3.2.

NOTE: If the text layer has different stroke color settings for each character, this attribute returns the setting for

the first character. Also, if you change the value, it resets all characters in the text layer to the specified setting.

Type: Array [r, g, b] of floating-point values; read/write.


strokeOverFill attribute

textDocument.strokeOverFill

Indicates the rendering order for the fill and stroke of a text layer. When true, the stroke appears over the fill.

NOTE: If the text layer has different fill/stroke rendering order settings for each character, this attribute returns

the setting for the first character. Also, if you change the value, it resets all characters in the text layer to the

specified setting.

Type: Boolean read/write.


strokeWidth attribute

textDocument.strokeWidth

The text layer’s stroke thickness in pixels.

187

After Effects scripting reference TextDocument object

NOTE: If the text layer has different stroke width settings for each character, this attribute returns the setting for

the first character. Also, if you change the value, it resets all characters in the text layer to the specified setting.

Type: Floating-point value (0 to 1000, inclusive); read/write.


text attribute

textDocument.text

The text value for the text layer’s Source Text property.

Type: String; read/write.

tracking attribute

textDocument.tracking

The text layer’s spacing between characters.

NOTE: If the text layer has different tracking settings for each character, this attribute returns the setting for the first character. Also, if you change the value, it resets all characters in the text layer to the specified setting.

Type: Floating-point value; read/write.