Handboek Annuleren

Use expressions to edit and access text properties

  1. After Effects User Guide
  2. Beta releases
    1. Beta Program Overview
    2. After Effects Beta Home
    3. Features in Beta
      1. Properties panel (Beta)
  3. Getting started
    1. Get started with After Effects
    2. What's new in After Effects 
    3. Release Notes | After Effects
    4. After Effects system requirements
    5. Keyboard shortcuts in After Effects
    6. Supported File formats | After Effects
    7. Hardware recommendations
    8. After Effects for Apple silicon
    9. Planning and setup
    10. Setup and installation
  4. Workspaces
    1. General user interface items
    2. Get to know After Effects interface
    3. Workflows
    4. Workspaces, panels, and viewers
  5. Projects and compositions
    1. Projects
    2. Composition basics
    3. Precomposing, nesting, and pre-rendering
    4. View detailed performance information with the Composition Profiler
    5. CINEMA 4D Composition Renderer
  6. Importing footage
    1. Preparing and importing still images
    2. Importing from After Effects and Adobe Premiere Pro
    3. Importing and interpreting video and audio
    4. Preparing and importing 3D image files
    5. Importing and interpreting footage items
    6. Working with footage items
    7. Detect edit points using Scene Edit Detection
    8. XMP metadata
  7. Text and Graphics
    1. Text
      1. Formatting characters and the Character panel
      2. Text effects
      3. Creating and editing text layers
      4. Formatting paragraphs and the Paragraph panel
      5. Extruding text and shape layers
      6. Animating text
      7. Examples and resources for text animation
      8. Live Text Templates
    2. Motion Graphics
      1. Work with Motion Graphics templates in After Effects
      2. Use expressions to create drop-down lists in Motion Graphics templates
      3. Work with Essential Properties to create Motion Graphics templates
      4. Replace images and videos in Motion Graphics templates and Essential Properties
  8. Drawing, Painting, and Paths
    1. Overview of shape layers, paths, and vector graphics
    2. Paint tools: Brush, Clone Stamp, and Eraser
    3. How to taper shape strokes
    4. Shape attributes, paint operations, and path operations for shape layers
    5. Use Offset Paths shape effect to alter shapes
    6. Creating shapes
    7. Create masks
    8. Remove objects from your videos with the Content-Aware Fill panel
    9. Roto Brush and Refine Matte
  9. Layers, Markers, and Camera
    1. Selecting and arranging layers
    2. Blending modes and layer styles
    3. 3D layers
    4. Layer properties
    5. Creating layers
    6. Managing layers
    7. Layer markers and composition markers
    8. Cameras, lights, and points of interest
  10. Animation, Keyframes, Motion Tracking, and Keying
    1. Animation
      1. Animation basics
      2. Animating with Puppet tools
      3. Managing and animating shape paths and masks
      4. Animating Sketch and Capture shapes using After Effects
      5. Assorted animation tools
      6. Work with Data-driven animation
    2. Keyframe
      1. Keyframe interpolation
      2. Setting, selecting, and deleting keyframes
      3. Editing, moving, and copying keyframes
    3. Motion tracking
      1. Tracking and stabilizing motion
      2. Face Tracking
      3. Mask Tracking
      4. Mask Reference
      5. Speed
      6. Time-stretching and time-remapping
      7. Timecode and time display units
    4. Keying
      1. Keying
      2. Keying effects
  11. Transparency and Compositing
    1. Compositing and transparency overview and resources
    2. Alpha channels, masks, and mattes
  12. Adjusting color
    1. Color basics
    2. Use the Adobe Color Themes extension
    3. Color management
    4. Color Correction effects
  13. Effects and Animation Presets
    1. Effects and animation presets overview
    2. Effect list
    3. Simulation effects
    4. Stylize effects
    5. Audio effects
    6. Distort effects
    7. Perspective effects
    8. Channel effects
    9. Generate effects
    10. Transition effects
    11. The Rolling Shutter Repair effect
    12. Blur and Sharpen effects
    13. 3D Channel effects
    14. Utility effects
    15. Matte effects
    16. Noise and Grain effects
    17. Detail-preserving Upscale effect
    18. Obsolete effects
  14. Expressions and Automation
    1. Expression
      1. Expression basics
      2. Understanding the expression language
      3. Using expression controls
      4. Syntax differences between the JavaScript and Legacy ExtendScript expression engines
      5. Editing expressions
      6. Expression errors
      7. Using the Expressions editor
      8. Use expressions to edit and access text properties
      9. Expression language reference
      10. Expression examples
    2. Automation
      1. Automation
      2. Scripts
  15. Immersive video, VR, and 3D
    1. Construct VR environments in After Effects
    2. Apply immersive video effects
    3. Compositing tools for VR/360 videos
    4. Tracking 3D camera movement
    5. Work in 3D Design Space
    6. 3D Transform Gizmos
    7. Do more with 3D animation
    8. Preview changes to 3D designs real time with the Real-Time Engine
    9. Add responsive design to your graphics 
  16. Views and Previews
    1. Previewing
    2. Video preview with Mercury Transmit
    3. Modifying and using views
  17. Rendering and Exporting
    1. Basics of rendering and exporting
    2. Export an After Effects project as an Adobe Premiere Pro project
    3. Converting movies
    4. Multi-frame rendering
    5. Automated rendering and network rendering
    6. Rendering and exporting still images and still-image sequences
    7. Using the GoPro CineForm codec in After Effects
  18. Working with other applications
    1. Dynamic Link and After Effects
    2. Working with After Effects and other applications
    3. Sync Settings in After Effects
    4. Creative Cloud Libraries in After Effects
    5. Plug-ins
    6. CINEMA 4D and Cineware
  19. Collaboration: Frame.io, and Team Projects
    1. Collaboration in Premiere Pro and After Effects
    2. Frame.io
      1. Install and activate Frame.io
      2. Use Frame.io with Premiere Pro and After Effects
      3. Frequently asked questions
    3. Team Projects
      1. Get Started with Team Projects
      2. Create a Team Project
      3. Collaborate with Team Projects
  20. Memory, storage, performance
    1. Memory and storage
    2. Improve performance
    3. Preferences
    4. GPU and GPU driver requirements for After Effects

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

Use expressions to control text styling in any text expression or in Motion Graphics templates. Some things you can do with expressions are:

  • Link multiple titles and update their styles at once (very useful for designing titles).
  • Keep font, size, and styling in sync across multiple text layers.
  • Make global changes to text properties.

Once you set these for a text layer, reference that layer's properties to easily apply changes throughout the composition.

After Effects uses the "get" and "set" functions to read and write values for text properties into the Expression Engine. You use expressions to drive and set font styles, such as text properties across text layers.

To access these functions for text properties:

  1. Add an expression to a Text Layer's Source Text property. For more information, see Expression basics.
  2. In the Expression Language flyout menu, select Text > Properties > Properties.

Save expressions as presets

Select the Source Text property 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.

For more information, see Effects and animation presets overview.

PostScript font expression menu

When referring to fonts in expressions, they must use a special "system name" ( or similar ). It is recommended to insert this special name from the Text > Font > Select Font dialog to avoid expression errors.

  • Open the Expression Language flyout menu, then select Text > Font. This brings up a dialog with drop-down menus to select the typeface and font to insert into the expression.
Font menu

Font syncing

Fonts that are only referred to in the Expressions Editor are not recorded as fonts used by the project. To ensure all fonts referred to in the Expressions Editor will Auto-Sync or populate the Resolve Fonts Dialog, use all of those fonts on a layer, even if that layer source is hidden.

Fonts Used

The style object

All of the styling properties for a text layer exist on the style object, which is accessed on the Source Text property using the following:

// Using the whole path to the Source Text property 
text.sourceText.style 
 
// Using the generic name for the current property 
thisProperty.style

Using style by itself is the same as using either of the two examples above, but this can be confusing if style attributes from multiple text layers are being combined.

The styling attributes of other text layers can also be read. Use the pick whip to create a link to the other text layer at the beginning of the first example shown above.

// Accessing the style object of a specific text layer 
 
thisComp.layer("Other Layer Name").text.sourceText.style;

Available text attributes

The following text styling attributes can be read and set using the style object:

  • Font
  • Font Size
  • Faux Bold
  • Faux Italics
  • All Caps
  • Small Caps
  • Tracking
  • Leading
  • Auto Leading
  • Baseline Shift
  • Fill (enable/disable)
  • Fill Color
  • Stroke (enable/disable)
  • Stroke Color
  • Stroke Width

The Source Text property of a text layer is interpreted by expressions as a JavaScript string. The text itself can be read with sourceText, but it must be set on the style object with the setText method if style attributes are being modified. See Examples below.

Combine style and source text

text and style
Combining Style and Source Text

To return the values of both the style and the actual Source Text at time, you will have to combine the getStyleAt and setText functions. Below are two examples of how to write this expression.

// To return the values of both the style and the actual Source Text at time (short hand) 
 
var sourceTextProperty = thisComp.layer("MAIN TEXT").text.sourceText; 
 
var newStyle = sourceTextProperty.getStyleAt(0,0);  
 
newStyle.setText(sourceTextProperty);
// To return the values of both the style and the actual Source Text of the previous layer in the layer stacking order 
 
var sourceTextProperty = thisComp.layer(index - 1).text.sourceText; 
 
var newStyle = sourceTextProperty.getStyleAt(0,0);  
 
newStyle.setText(sourceTextProperty);

Dropdown fonts

dropdown fonts
Link Fonts or Styles to a Dropdown Menu

You can use Dropdown menus to control text styles, such as locking text layers to specific fonts. This is useful for brand guidelines, templates, MoGRTS, and more:

// To lock a text layer to specific fonts with a Dropdown Menu Control 
 
var dropDownMenu = thisComp.layer("LayerName").effect("Dropdown Menu Control")("Menu"); 
 
switch (dropDownMenu.value) { 
 
    case 1 : 
 
        text.sourceText.style.setFont("Georgia"); 
 
        break; 
 
    case 2 : 
 
        text.sourceText.style.setFont("Impact"); 
 
        break; 
 
default : 
 
        text.sourceText.style.setFont("Tahoma"); 
 
}

Main text layer

master text layer
Get text properties from “Text Layer 1” but override Font Size and Fill Color

Link multiple text layers to a main font controller to control the text style of multiple layers at once. Create two text layers, and paste this expression into the Source Text of one of them:

// To get all text properties from a text layer 
 
thisComp.layer("Text Layer 1").text.sourceText.style;

It is possible to get the style from a text layer but override specific text properties by adding values with the Set functions. Below are two examples using Fill Color and Font Size.

// To get all text properties from “Text Layer 1” but override Fill Color and Font Size with hardcoded values 
 
var newStyle = thisComp.layer("Text Layer 1").text.sourceText.style;  
 
newStyle.setFillColor(hexToRgb("FF0000")).setFontSize(100);
// To get all text properties from "Text Layer 1” but override Fill Color and Font Size with the layer’s current text properties 
 
var newStyle = thisComp.layer("Text Layer 1").text.sourceText.style; 
 
var currentFillColor = thisProperty.style.fillColor; 
 
var currentFontSize = thisProperty.style.fontSize; 
 
newStyle.setFillColor(currentFillColor).setFontSize(currentFontSize);

Examples

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

Font

The following are examples for accessing a text layer's Font, Font Size, Faux Bold, Faux Italic, Tracking, and Leading:

// To return the name of the Font for the text layer itself 
text.sourceText.style.font; 
 
// To return the name of the Font another text layer is using 
var otherLayer = thisComp.layer("Other Layer Name"); 
 
otherLayer.text.sourceText.style.font; 
 
// To return the value of Font Size for the text layer itself 
text.sourceText.style.fontSize; 
 
// To return the value of Font Size for another text layer 
var otherLayer = thisComp.layer("Other Layer Name"); 
 
otherLayer.text.sourceText.style.fontSize; 
 
// To return a Boolean value of whether a layer's text is Faux Bold or not (True or False) 
text.sourceText.style.isFauxBold; 
 
// To return a Boolean value of whether a layer's text is Faux Italic or not (True or False) 
text.sourceText.style.isFauxItalic; 
 
// To return the value of a text layer’s Tracking as a number 
text.sourceText.style.tracking; 
 
// To return the value of a text layer's Leading as a number 
text.sourceText.style.leading;

Fill

The following are examples for accessing a text layer's Fill and Fill Color:

// To return a Boolean value of whether a layer's text has Fill applied to it (True or False) 
text.sourceText.style.applyFill; 
 
// To return the value of the Fill Color of a text layer 
// By default, this returns an array of the RGB values on a scale from 0 – 1.0 
text.sourceText.style.fillColor; 
 
// Set the Fill Color of a text layer with setApplyFill and setFillColor 
// setFillColor values are defined as an RGB array on a scale between 0 – 1.0 
var newStyle = style.setApplyFill(true); 
 
newStyle.setFillColor([1.0, 1.0, 1.0]); 
 
// Set the Fill Color of a text layer substituting the 0 – 1.0 RGB array with hexToRGB to define the color values with Hex values 
var newStyle = style.setApplyFill(true); 
 
newStyle.setFillColor(hexToRgb("FFFFFF"));
Opmerking:

To return the value of the Fill Color for R, G, or B of a text layer, add 0, 1, or 2 in brackets, respectively.

// To return the red (R) value of the Fill Color 
 
text.sourceText.style.fillColor[0];

Stroke

The following are examples for accessing a text layer's Stroke, Stroke Color, and Stroke Width:

// To return a Boolean value of whether a layer's text has Stroke applied to it (True or False) 
text.sourceText.style.applyStroke; 
 
// To return the value of the Stroke Color of a text layer 
// By default, this returns an array of the RGB values on a scale from 0 – 1.0 
text.sourceText.style.strokeColor; 
 
// Set the Stroke Color of a text layer with setApplyStroke and setStrokeColor 
// setStrokeColor values are defined as an RGB array on a scale between 0 – 1.0 
var newStyle = style.setApplyStroke(true); 
 
newStyle.setStrokeColor([1.0, 0.0, 0.0]); 
 
// Set the Stroke Color of a text layer substituting the 0 – 1.0 RGB array with hexToRGB to define the color values with Hex values 
var newStyle = style.setApplyStroke(true); 
 
newStyle.setStrokeColor(hexToRgb("FF0000")); 
 
// To return the value of a text layer's Stroke Width as a number 
text.sourceText.style.strokeWidth;
Opmerking:

To return the value of the Stroke Color for R, G, or B of a text layer, add 0, 1, or 2 in brackets, respectively.

// To return the green (G) value of the Stroke Color 
 
text.sourceText.style.strokeColor[1];

Get functions

Use this “get” function to return the style value of a particular character at a specific time. "index" should be a number, the index of the letter or character whose style is needed. "atTime" should also be a number, the time within the composition to get the style from in case the style is keyframed and changes over time.

text.sourceText.getStyleAt(index, atTime);
Opmerking:

Using text.sourceText.style is the same as using text.sourceText.getStyleAt(0,0).

// Gets the style of the first character at the beginning of the timeline 
 
text.sourceText.getStyleAt(0,0);

Set functions

Additional "set" functions that can be used individually or in combination with one another to drive styles across layers. Each of these functions are called on the style object of a Source Text property:

// Set the font used to Arial 
style.setFont("ArialMT") 
 
// Set the font size to 80 
style.setFontSize(80); 
 
// Enable Faux Bold with a Boolean 
style.setFauxBold(true) 
 
// Enable Faux Italics with a Boolean 
style.setFauxItalics(true) 
 
// Enable All Caps with a Boolean 
style.setAllCaps(true) 
 
// Enable Small Caps with a Boolean 
style.setSmallCaps(true) 
 
// Set the Tracking as a number 
style.setTracking(10); 
 
// Set the Leading as a number 
style.setLeading(10); 
 
// Enable Auto Leading with a Boolean 
style.setAutoLeading(true); 
 
// Set the Baseline Shift as a number 
style.setBaselineShift(10); 
 
// Set the Stroke Width as a number 
style.setStrokeWidth(10); 

All of the Set functions for text styles can be chained together to easily set multiple attributes without having to declare a new style each time, as in the following example:

Opmerking:

There is no semicolon used until the very last attribute is set. Listing each attribute on its own line helps make the whole chain easier to read.

// Enable Fill, set Fill Color, set Baseline, set Tracking, and enable Auto Leading 
 
text.sourceText.style 
 
    .setApplyFill(true) 
 
    .setFillColor(hexToRgb("FFFFFF")) 
 
    .setBaselineShift(10) 
 
    .setTracking(25) 
 
    .setAutoLeading(true);

Paragraph text expression tip

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()

Additional uses for expressions on source text

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:

var nextLayer =  thisComp.layer(index + 1); 
nextLayer.name + "\rOpacity = " + nextLayer.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:

// Create sourceFootageName as a blank string 
var sourceFootageName = ""; 
  
// Loop through all layers in the composition 
for (var i = 1; i <= thisComp.numLayers; i++) { 
  
    // If i matches this layer's index, continue to next loop 
    if (i == index) { 
        continue; 
    } 
  
    // Set myLayer for the current iteration of the loop 
    var myLayer = thisComp.layer(i); 
  
    // If myLayer has no video or isn't active, continue to next loop/layer 
    if ( !myLayer.hasVideo || !myLayer.active ) { 
      continue; 
    } 
  
    // If myLayer is active at the current time 
    if ( myLayer.active ) { 
        try { 
            // Set sourceFootageName to myLayer's source name 
            sourceFootageName = myLayer.source.name; 
        } catch ( err ) { 
            // If myLayer has no source, 
            // set sourceFootageName to the myLayer's name 
            sourceFootageName = myLayer.name; 
        } 
  
        // Stop looping 
        break; 
    } 
} 
  
// Display the sourceFootageName 
sourceFootageName;

More Expression resources

Now that you have understood some of the concepts behind expressions, come to the community for some real-life examples, and to share your work.

For further breakdowns of how to use text style expressions and dropdowns, see this Adobe Blog post: After Effects 2020: Express Yourself (and Your Text).

You can also check out Dan Ebberts' excellent collection of example expressions and tutorials on his MotionScript website.

The AE Enhancers forum also provides many examples and much information about expressions, as well as scripts and animation presets.

Adobe-logo

Aanmelden bij je account