Edit the text styles and text properties using the expression controls.

You can use expressions to control text styling as well as the text itself. Work with any text expression as well as with Motion Graphics Templates. You can link multiple titles together and update their styling at once, which is used for title design, especially main and end titles. You can make global changes to text properties when you use expressions.

This feature also enables you to keep font, size and styling in sync across multiple text layers in After Effects and Motion Graphics templates. Once you set these for a text layer, you can reference that layer properties to easily apply changes throughout the compositon.

After Effects uses the Get and Set functions to read and write values for text properties into the Expression Engine so that you can use expressions to drive and set font styles, such as text properties across text layers.

To access these functions for text properties, if expressions are enabled, right-click a text layer, and open the Expression menu, and select Text > Properties > Properties.

If there is code already recorded in the expressions editor, the new expression is inserted at the caret.

Access text properties
Access text properties

When you select a desired function, it adds to the expressions editor for that layer. If there is code already recorded in the expression editor, the new expression is inserted automatically.

Save expressions as presets

Select the text layer with expressions added to it. Then, select Animation > Save Animation Preset to reuse the expressions in other projects. Animation Presets are saved in the Effects and Presets panel.

PostScript font expression menu

  • To refer to specific fonts in an expression, you can use the Font dropdown menu in the Expressions menu to insert the PostScript name of the desired font into the expression.
  • Select Text > Font in the Expressions Editor to insert into your expressions.

Other important points

  • Fonts that are referred to in the expressions only are not recorded as Fonts Used by the project and therefore do not Auto-Sync or populate the Resolve Fonts Dialog if the font is not installed.
  • The Workaround is to use all of the fonts referred to in the project on a layer or a comp even if that source is hidden. The reference to the font cannot only exist in the Expressions Editor.

The following are examples for how to access and use text property values with expressions:

Action

Expression

To return the value of the Font name for the same layer itself

style = text.sourceText.style.font;

To return the value of the Font name for another layer

fontName = thisComp.layer("source layer name").text.sourceText.style.font;

To return value of Font Size for the same layer itself

fontSize = text.sourceText.style.fontSize;

To return the value of Font Size for another layer

style = thisComp.layer("source layer name").text.sourceText.style.fontSize;

To return a boolean value of whether a layer's text is Faux Bold or not (True or False)

style = thisComp.layer("source layer name").text.sourceText.style.isFauxBold;

To return a boolean value of whether a layer's text is Faux Italic or not (True or False)

style = thisComp.layer("source layer name").text.sourceText.style.isFauxItalic;

To return a boolean value of whether a layer's text has Fill applied to it (true or false)

style.applyFill;

To return the value of the fill color of a text layer.

By default this returns the first value of RGB on a scale from 0-1.0

To get the value for G or B add 1 or 2 in parenthesis at the end of expression

style.fillColor; style.fillColor(2);

To return a boolean value of whether a layer's text has Stroke applied to it (true or false)

style.applyStroke;

To return the value of the fill color of a text layer.

By default this returns the first value of RGB on a scale from 0-1.0

To get the value for G or B add 1 or 2 in parenthesis

style.strokeColor; style.strokeColor(1);

To return the value of a text layer's Stroke

style.strokeWidth;

To return tracking value

style.tracking;

To return leading value

style.leading;

To return boolean value if auto leading is on or off (true or false)

style.autoLeading;

Get Function to return the value at a particular Character Index

getStyleAt(0);

Get Function to return the value at particular Character Index at Time (n = character index, x = time in seconds)

getStyleAt(n,x);

Example: To return the value at a particular Character Index and time (optional) same layer (n = character index, x = time in seconds)

style = text.sourceText.getStyleAt(n,x);

Get style at Character Index 0 of another layer

style = thisComp.layer("source layer name").text.sourceText.style; style;

Example: To return the value at a particular Character Index and time (optional) of a different layer different layer

style = thisComp.layer("source layer name").text.sourceText.getStyleAt(0,5);

Using .style at the end is the same as using getStyleAt(0);

style = text.sourceText.style;

Add "font or "fontStyle" after the getStyleAt(0) to return specific text property values

getStyleAt(4).fontSize; getStyleAt(3).font;

To return the values of both the style and the actual source text at time (short hand)

style = thisComp.layer("source layer name").text.sourceText.getStyleAt(0,0);

style.setText(thisComp.layer("source layer name").text.sourceText);

Set Functions for both style and text (long form):

style.setFont(thisComp.layer("source layer name").text.sourceText.style.font); style;

To create empty style (in order to use Set Functions to bake in specific values)

style = text.sourceText.createStyle();

create style and set specific values through Set Functions ** (long form):

styleA = thisComp.layer("source layer name").text.sourceText.createStyle(); styleB = styleA.setFontSize(300); styleC = styleB.setFont("Impact"); styleC;

create style and set specific values through Set Functions ** (short form):

text.sourceText.createStyle().setFontSize(300).setFont("Impact");

Returning Character Index value with Get Function + overriding some of the specific values with Set Functions

style = text.sourceText.getStyleAt(3); style = style.setFontSize(150); style = style.setFont(thisComp.layer("source later text").text.sourceText.style.font); style; 

You can also reference layers by index instead of name for localization (but re-arranging or adding new layers will break the expression.

style = thisComp.layer(1).text.sourceText.getStyleAt(0); style.setText(thisComp.layer(1).text.sourceText);

Additional Set Functions that can be used individually or in combination with one another to drive styles across layers.

newStyle = style.setBaselineShift(new_value);

newStyle = style.setApplyFill(true/false); 

newStyle = style.setFillColor([1.0,1.0,1.0]) // array of RGB values

newStyle = style.setApplyStroke(true/false)

newStyle = style.setStrokeColor([1.0,1.0,1.0]) // array of RGB values

newStyle = style.setStrokeWidth(new_value) 

newStyle = style.setTracking(new_value);

newStyle = style.setLeadig(new_value);

newStyle = style.setAutoLeading(true);

Set the Baseline Shift Value for a text layer 

newStyle = style.setBaselineShift(new_value);

Use this to turn a text layer's Fill on or off

newStyle = style.setApplyFill(true/false); 

Use this in combination with setApplyFill to define the Fill Color.

These values are defined on a 0-1.0 RGB 

You can use this in combination with the hexToRGB to define the color values with Hex values instead of the 0-1.0 RGB scale

newStyle = style.setFillColor([1.0,1.0,1.0]) // array of RGB values 

Use this to turn a text layer's Stroke on or off

newStyle = style.setApplyStroke(true/false) 

Use this in combination with setApplyStroke to define the Stroke Color.

These values are defined on a 0-1.0 RGB 

You can use this in combination with the hexToRGB to define the color values with Hex values instead of the 0-1.0 RGB scale

newStyle = style.setStrokeColor([1.0,1.0,1.0]) // array of RGB values 

Use this to set a text layers stroke width

newStyle = style.setStrokeWidth(new_value) 

Use this to set the Tracking value

newStyle = style.setTracking(new_value); 

Use this to set the Leading Value

newStyle = style.setLeadig(new_value); 

Use this to turn AutoLeading on or off

newStyle = style.setAutoLeading(true);

Example of how these can be used together

text.sourceText.style.setFillColor(hexToRgb("00FF00")).setApplyStroke(1).setStrokeWidth(5).setStrokeColor([1,0,0]).setFontSize(200); 

Write expressions for source text

The Source Text property of a text layer is interpreted by expressions as a JavaScript String. You can use the pick whip to retrieve the source text from another text layer; however, only the style of the first character of the destination layer is used.

In the Essential Graphics Panel, in the Source Text Properties menu, you can select the Use layer as fallback text box. When checked on, you can select a comp/subcomp and a shape or clip layer to determine an alternate text box for editing the text in Premiere Pro Program Monitor.

Source text properties

You can use "\r" in a string expression to start a new line of text. For example, to copy the original text from one layer onto the same layer and repeat it in all uppercase characters on a new line, use the following expression:

  text.sourceText + "\r" + text.sourceText.toUpperCase()

Adding a text layer to a composition and adding an expression to its Source Text property can be a great way to examine the property values of other layers. For example, the following expression on a Source Text property reports the name and value of the Opacity property for the next layer in the layer stacking order:

  thisComp.layer(index + 1).name + "\rOpacity = " + thisComp.layer(index + 1).opacity.value

The following example reports the name of the footage item used as the source of the topmost image layer in the stacking order at the current time that has its Video switch set.

  source_footage_name = ""; 
  for (i = 1; i <= thisComp.numLayers; i++){ 
      if (i == index) continue; 
      my_layer = thisComp.layer(i); 
      if (! (my_layer.hasVideo && my_layer.active)) continue; 
      if (time >= my_layer.inPoint && time < my_layer.outPoint){ 
          try{ 
              source_footage_name = my_layer.source.name; 
          }catch(err1){ 
              source_footage_name = my_layer.name 
          } 
          break; 
      } 
  } 
  source_footage_name

Dette arbejde har licens under en Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Opslag på Twitter™ og Facebook er ikke omfattet af vilkårene for Creative Commons.

Juridiske meddelelser   |   Politik for beskyttelse af personlige oplysninger online