User Guide Cancel

Expression language reference

  1. After Effects User Guide
  2. Beta releases
    1. Beta Program Overview
    2. After Effects Beta Home
  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
  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
      5. Animate faster and easier using the Properties panel
  8. Drawing, Painting, and Paths
    1. Overview of shape layers, paths, and vector graphics
    2. Paint tools: Brush, Clone Stamp, and Eraser
    3. 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 and masks
    3. Track Mattes and Traveling Mattes
  12. Adjusting color
    1. Color basics
    2. Color management
    3. Color Correction effects
    4. OpenColorIO and ACES color management
  13. Effects and Animation Presets
    1. Effects and animation presets overview
    2. Effect list
    3. Effect Manager
    4. Simulation effects
    5. Stylize effects
    6. Audio effects
    7. Distort effects
    8. Perspective effects
    9. Channel effects
    10. Generate effects
    11. Time effects
    12. Transition effects
    13. The Rolling Shutter Repair effect
    14. Blur and Sharpen effects
    15. 3D Channel effects
    16. Utility effects
    17. Matte effects
    18. Noise and Grain effects
    19. Detail-preserving Upscale effect
    20. Obsolete effects
  14. Expressions and Automation
    1. Expressions
      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. Advanced 3D Renderer
    5. Import and add 3D models to your composition
    6. Import 3D models from Creative Cloud Libraries
    7. Image-Based Lighting
    8. Extract and animate lights and cameras from 3D models
    9. Tracking 3D camera movement
    10. Cast and accept shadows
    11. Embedded 3D model animations
    12. Shadow Catcher
    13. 3D depth data extraction
    14. Modify materials properties of a 3D layer
    15. Work in 3D Design Space
    16. 3D Transform Gizmos
    17. Do more with 3D animation
    18. Preview changes to 3D designs real time with the Mercury 3D engine
    19. 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. H.264 Encoding in After Effects
    3. Export an After Effects project as an Adobe Premiere Pro project
    4. Converting movies
    5. Multi-frame rendering
    6. Automated rendering and network rendering
    7. Rendering and exporting still images and still-image sequences
    8. 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
      1. Export After Effects project as Premiere Pro project
    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. How After Effects handles low memory issues while previewing    
    3. Improve performance
    4. Preferences
    5. GPU and GPU driver requirements for After Effects
  21. Knowledge Base
    1. Known issues
    2. Fixed issues
    3. Frequently asked questions
    4. After Effects and macOS Ventura
    5. How After Effects handles low memory issues while previewing

Learn about expressions and expression references such as time conversion methods and vector math methods in After Effects.

Looping Keyframes with Expressions in After Effects

Use the After Effects expression elements along with standard JavaScript elements to write your expressions. You can use the Expression Language menu at any time to insert methods and attributes into an expression, and you can use the pick whip at any time to insert properties.

If an argument description contains an equal sign (=) and a value (such as t=time or width=.2), then the argument uses the included default value if you don't specify a different value.

Some argument descriptions include a number in square brackets, indicating the dimension of the expected property or Array.

Some return-value descriptions include a number in square brackets—this number specifies the dimension of the returned property or Array. If a specific dimension isn't included, the dimension of the returned Array depends on the dimension of the input.

The W3Schools JavaScript reference website provides information for the standard JavaScript language, including pages for the JavaScript Math and String objects.

Expressions: JavaScript Engine

After Effects uses JavaScript engine when evaluating expressions. The performance of evaluating expressions during renders can be up to 5x faster than the Legacy ExtendScript engine.

On Windows, After Effects uses the V8 open-source JavaScript engine. This provides a more modern version of JavaScript than available in ExtendScript, which only supports the third edition of the ECMA-262 Standard. 

You can use Project Settings to choose whether a project uses the JavaScript engine or Legacy ExtendScript.

  1. Select File > Project Settings

  2. Select the Expressions tab and select the Expressions Engine as JavaScript or Legacy ExtendScript.

    Note:

    Projects saved in previous versions of After Effects default to Legacy ExtendScript.

Improvements provided by the JavaScript engine

  • Higher mathematical precision in floating-point operations. 
  • Array and string methods from modern JavaScript can be used.
  • Other modern JavaScript objects like typed arrays, usage of keywords 'let' and 'const', and many other additions made in recent versions of the ECMA-262 Standard are available.

Differences between the JavaScript engine and ExtendScript

  • The syntax for if/else statements is strict in the JavaScript engine and need to be written for standardized JavaScript.
  • When accessing the indexes of characters on a Text Layer as an array, use text.sourceText.value[i] instead of text.sourceText[i].
  • Older snake_case expression methods  such as this_comp and to_world, which had been previously deprecated in ExtendScript) are not supported.
  • Simplified 'this(arg)' syntax is not supported.

Global objects, attributes, and methods (expression reference)

comp(name)

Return type: Comp.

Argument type: name is a String.

Retrieves another composition by name.

footage(name)

Return type: Footage.

Argument type: name is a String.

Retrieves a footage item by name.

thisComp

Return type: Comp.

Represents the composition containing the expression.

thisLayer

Return type: Layer, Light, or Camera.

Represents the layer containing the expression. Because thisLayer is the default object, its use is optional. For example, you can start an expression with thisLayer.width or width and get the same result.

thisProperty

Return type: Property.

Represents the property containing the expression. For example, if you write an expression on the Rotation property, you can start an expression with thisProperty to refer to the Rotation property.

time

Return type: Number.

Represents the composition time, in seconds, at which the expression is being evaluated.

colorDepth

Return type: Number.

Returns the project color depth value. For example, colorDepth returns 16 when the project color depth is 16 bits per channel.

posterizeTime(framesPerSecond)

Return type: Number.

Argument type: framesPerSecond is a Number.

The framesPerSecond value becomes the frame rate from which the rest of the expression operates. This expression allows you to set the frame rate for a property to be lower than the frame rate of the composition. For example, the following expression updates the property value with a random value once per second:

  posterizeTime(1);   random()

value

Return type: Number, Array, or String.

Represents the value at the current time for the property containing the expression.

Time conversion methods (expression reference)

timeToFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false)

Return type: Number.

Argument type: t and fps are Numbers; isDuration is a Boolean.

Converts the value of t, which defaults to the current composition time, to an integer number of frames. The number of frames per second is specified in the fps argument, which defaults to the frame rate of the current composition (1.0 / thisComp.frameDuration). The isDuration argument, which defaults to false, should be true if the t value represents a difference between two times instead of an absolute time. Absolute times are rounded down toward negative infinity; durations are rounded away from zero (up for positive values).

framesToTime(frames, fps = 1.0 / thisComp.frameDuration)

Return type: Number.

Argument type: frames and fps are Numbers.

The inverse of timeToFrames. Returns the time corresponding to the frames argument, which is required. It doesn’t have to be an integer. See timeToFrames for explanation of the fps argument.

timeToTimecode(t = time + thisComp.displayStartTime, timecodeBase = 30, isDuration = false)

Return type: String.

Argument type: t and timecodeBase are Numbers; isDuration is a Boolean.

Converts the value of t to a String representing timecode. See timeToFrames for an explanation of the t and isDuration arguments. The timecodeBase value, which defaults to 30, specifies the number of frames in one second.

timeToNTSCTimecode(t = time + thisComp.displayStartTime, ntscDropFrame = false, isDuration = false)

Return type: String.

Argument type: t is a Number, ntscDropFrame and isDuration are Booleans.

Converts t to a String representing NTSC timecode. See timeToFrames for an explanation of the t and isDuration arguments. If ntscDropFrame is false (the default), the result String is NTSC non-drop-frame timecode. If ntscDropFrame is true, the result String is NTSC drop-frame timecode.

timeToFeetAndFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, framesPerFoot = 16, isDuration = false)

Return type: String.

Argument type: t, fps, and framesPerFoot are Numbers; isDuration is a Boolean.

Converts the value of t to a String representing feet of film and frames. See timeToFrames for an explanation of the t, fps, and isDuration arguments. The framesPerFoot argument specifies the number of frames in one foot of film. It defaults to 16, which is the most common rate for 35mm footage.

timeToCurrentFormat(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false)

Return type: String.

Argument type: t and fps are Numbers; isDuration is a Boolean.

Converts the value of t to a String representing time in the current Project Settings display format. See timeToFrames for a definition of all the arguments.

An optional ntscDropFrame argument was added to the timeToCurrentFormat() function in After Effects CS5.5 and later. Default: ntscDropFrame = thisComp.ntscDropFrame.

Note:

If you want more control over the look of the timecode in your footage, use the timeToCurrentFormat method or other timeTo methods to generate the timecode instead of using the Timecode or Numbers effect. Create a text layer, add an expression to the Source Text property, and enter timeToCurrentFormat() in the expression field. With this method, you can format and animate the timecode text. In addition, the timecode uses the same display style defined by the current project settings.

Vector Math methods (expression reference)

Vector Math functions are global methods that perform operations on arrays, treating them as mathematical vectors. Unlike built-in JavaScript methods, such as Math.sin, these methods are not used with the Math prefix. Unless otherwise specified, Vector Math methods are lenient about dimensions and return a value that is the dimension of the largest input Array object, filling in missing elements with zeros. For example, the expression add([10, 20], [1, 2, 3]) returns [11, 22, 3].

add(vec1, vec2)

Return type: Array.

Argument type: vec1 and vec2 are Arrays.

Adds two vectors.

sub(vec1, vec2)

Return type: Array.

Argument type: vec1 and vec2 are Arrays.

Subtracts two vectors.

mul(vec, amount)

Return type: Array.

Argument type: vec is an Array, amount is a Number.

Multiplies every element of the vector by the amount.

div(vec, amount)

Return type: Array.

Argument type: vec is an Array, amount is a Number.

Divides every element of the vector by the amount.

clamp(value, limit1, limit2)

Return type: Number or Array.

Argument type: value, limit1, and limit2 are Numbers or Arrays.

The value of each component of value is constrained to fall between the values of the corresponding values of limit1 and limit2.

dot(vec1, vec2)

Return type: Number.

Argument type: vec1 and vec2 are Arrays.

Returns the dot (inner) product of the vector arguments.

cross(vec1, vec2)

Return type: Array [2 or 3].

Argument type: vec1 and vec2 are Arrays [2 or 3].

Returns the vector cross product of vec1 and vec2. Refer to a math reference or JavaScript guide for more information.

normalize(vec)

Return type: Array.

Argument type: vec is an Array.

Normalizes the vector so that its length is 1.0. Using the normalize method is a short way of performing the operation div(vec, length(vec)).

length(vec)

Return type: Number.

Argument type: vec is an Array.

Returns the length of vector vec.

length(point1, point2)

Return type: Number.

Argument type: point1 and point2 are Arrays.

Returns the distance between two points. The point2 argument is optional. For example, length(point1, point2) is the same as length(sub(point1, point2)).

For example, add this expression to the Focus Distance property of a camera to lock the focal plane to the camera's point of interest so that the point of interest is in focus:

  length(position, pointOfInterest)

lookAt(fromPoint, atPoint)

Return type: Array [3].

Argument type: fromPoint and atPoint are Arrays [3].

The argument fromPoint is the location in world space of the layer you want to orient. The argument atPoint is the point in world space you want to point the layer at. The return value can be used as an expression for the Orientation property, making the z-axis of the layer point at atPoint. This method is especially useful for cameras and lights. If you use this expression on a camera, turn off auto-orientation. For example, this expression on the Orientation property of a spot light makes the light point at the anchor point of layer number 1 in the same composition: lookAt(position, thisComp.layer(1).position)

Random Numbers methods (expression reference)

Note:

The wiggle method, which is used to randomly vary a property value —is in the Property attributes and methods category. For more information, refer to Property attributes and methods (expression reference).

seedRandom(offset, timeless=false)

Return type: none.

Argument type: offset is a Number, timeless is a Boolean.

The random and gaussRandom methods use a seed value that controls the sequence of numbers. By default, the seed is computed as a function of a unique layer identifier, the property within the layer, the current time, and an offset value of 0. Call seedRandom to set the offset to something other than 0 to create a different random sequence.

Use true for the timeless argument to not use the current time as input to the random seed. Using true for the timeless argument allows you to generate a random number that doesn’t vary depending on the time of evaluation.

The offset value, but not the timeless value, is also used to control the initial value of the wiggle function.

For example, this expression on the Opacity property sets the Opacity value to a random value that does not vary with time:

  seedRandom(123456, true);   random()*100

The multiplication by 100 in this example converts the value in the range 0–1 returned by the random method into a number in the range 0–100; this range is more typically useful for the Opacity property, which has values from 0% to 100%.

random()

Return type: Number.

Returns a random number in the range 0–1.

In After Effects CC and CS6, the behavior of random() is changed to be more random when layer IDs are close together. The wiggle() expression is not affected.

random(maxValOrArray)

Return type: Number or Array.

Argument type: maxValOrArray is a Number or Array.

If maxValOrArray is a Number, this method returns a number in the range from 0 to maxValOrArray. If maxValOrArray is an Array, this method returns an Array with the same dimension as maxValOrArray, with each component ranging from 0 to the corresponding component of maxValOrArray.

random(minValOrArray, maxValOrArray)

Return type: Number or Array.

Argument type: minValOrArray and maxValOrArray are Numbers or Arrays.

If minValOrArray and maxValOrArray are Numbers, this method returns a number in the range from minValOrArray to maxValOrArray. If the arguments are Arrays, this method returns an Array with the same dimension as the argument with the greater dimension, with each component in the range from the corresponding component of minValOrArray to the corresponding component of maxValOrArray. For example, the expression random([100, 200], [300, 400]) returns an Array whose first value is in the range 100–300 and whose second value is in the range 200–400. If the dimensions of the two input Arrays don’t match, higher-dimension values of the shorter Array are filled out with zeros.

gaussRandom()

Return type: Number.

Returns a random number. The results have a Gaussian (bell-shaped) distribution. Approximately 90% of the results are in the range 0–1, and the remaining 10% are outside this range.

gaussRandom(maxValOrArray)

Return type: Number or Array.

Argument type: maxValOrArray is a Number or Array.

When maxValOrArray is a Number, this method returns a random number. Approximately 90% of the results are in the 0 to maxValOrArray range, and the remaining 10% are outside this range. When maxValOrArray is an Array, this method returns an Array of random values, with the same dimension as maxValOrArray. 90% of the values are in the range from 0 to maxValOrArray, and the remaining 10% are outside this range. The results have a Gaussian (bell-shaped) distribution.

gaussRandom(minValOrArray, maxValOrArray)

Return type: Number or Array.

Argument type: minValOrArray and maxValOrArray are Numbers or Arrays.

If minValOrArray and maxValOrArray are Numbers, this method returns a random number. Approximately 90% of the results are in the range from minValOrArray to maxValOrArray, and the remaining 10% are outside this range. If the arguments are Arrays, this method returns an Array of random numbers with the same dimension as the argument with the greater dimension. For each component, approximately 90% of the results are in the range from the corresponding component of minValOrArray to the corresponding component of maxValOrArray, and the remaining 10% are outside this range. The results have a Gaussian (bell-shaped) distribution.

noise(valOrArray)

Return type: Number.

Argument type: valOrArray is a Number or an Array [2 or 3].

Returns a number in the range from -1 to 1. The noise is not actually random; it is based on Perlin noise, which means that the return values for two input values that are near one another tend to be near one another. This type of noise is useful when you want a sequence of seemingly random numbers that don’t vary wildly from one to the other—as is usually the case when animating any apparently random natural motion. Example: rotation + 360*noise(time)

Interpolation methods (expression reference)

For all the Interpolation methods, the argument t is often time or value, though it can have other values, instead. If t is time, the interpolation between values happens over a duration. If t is the value, then the expression maps one range of values to a new range of values.

linear(t, tMin, tMax, value1, value2)

Return type: Number or Array.

Argument type: t, tMin, and tMax are Numbers, and value1 and value2 are Numbers or Arrays.

Returns value1 when t <= tMin. Returns value2 when t >= tMax. Returns a linear interpolation between value1 and value2 when tMin < t < tMax.

For example, this expression on the Opacity property causes Opacity values to ramp linearly from 20% to 80% over the time from 0 seconds to 6 seconds:

  linear(time, 0, 6, 20, 80)

This method—like all the Interpolation methods—can also be used to convert from one range of values to another. For example, this expression on the Opacity property converts the Opacity values from the range 0%-100% to the range 20%-80%:

  linear(value, 0, 100, 20, 80)

linear(t, value1, value2)

Return type: Number or Array.

Argument type: t is a Number, and value1 and value2 are Numbers or Arrays.

Returns a value that linearly interpolates from value1 to value2 as t ranges from 0 to 1. Returns value1 when t <= 0. Returns value2 when t >= 1.

ease(t, value1, value2)

Return type: Number or Array.

Argument type: t is a Number, and value1 and value2 are Numbers or Arrays.

Similar to linear with the same arguments, except that the interpolation eases in and out so that the velocity is 0 at the start and end points. This method results in a smooth animation.

ease(t, tMin, tMax, value1, value2)

Return type: Number or Array.

Argument type: t, tMin, and tMax are Numbers, and value1 and value2 are Numbers or Arrays.

Similar to linear with the same arguments, except that the interpolation eases in and out so that the velocity is 0 at the start and end points. This method results in a smooth animation.

easeIn(t, value1, value2)

Return type: Number or Array.

Argument type: t is a Number, and value1 and value2 are Numbers or Arrays.

Similar to ease, except that the tangent is 0 only on the value1 side and interpolation is linear on the value2 side.

easeIn(t, tMin, tMax, value1, value2)

Return type: Number or Array.

Argument type: t, tMin, and tMax are Numbers, and value1 and value2 are Numbers or Arrays.

Similar to ease, except that the tangent is 0 only on the tMin side and interpolation is linear on the tMax side.

easeOut(t, value1, value2)

Return type: Number or Array.

Argument type: t is a Number, and value1 and value2 are Numbers or Arrays.

Similar to ease, except that the tangent is 0 only on the value2 side and interpolation is linear on the value1 side.

easeOut(t, tMin, tMax, value1, value2)

Return type: Number or Array.

Argument type: t, tMin, and tMax are Numbers, and value1 and value2 are Numbers or Arrays.

Similar to ease, except that the tangent is 0 only on the tMax side and interpolation is linear on the tMin side.

Color Conversion methods (expression reference)

rgbToHsl(rgbaArray)

Return type: Array [4].

Argument type: rgbaArray is an Array [4].

Converts a color in RGBA space to HSLA space. The input is an Array of normalized red, green, blue, and alpha channel values, all in the range of 0.0 to 1.0. The resulting value is an Array of hue, saturation, lightness, and alpha channel values, also in the range of 0.0 to 1.0. Example:

  rgbToHsl.effect("Change Color")("Color To Change")

hslToRgb(hslaArray)

Return type: Array [4].

Argument type: hslaArray is an Array [4].

Converts a color in HSLA space to RGBA space. This conversion is the opposite of the conversion performed by the rgbToHsl method.

Other Math methods (expression reference)

degreesToRadians(degrees)

Return type: Number.

Argument type: degrees is a Number.

Converts degrees to radians.

radiansToDegrees(radians)

Return type: Number.

Argument type: radians is a Number.

Converts radians to degrees.

Comp attributes and methods (expression reference)

layer(index)

Return type: Layer, Light, or Camera.

Argument type: index is a Number.

Retrieves the layer by number (order in the Timeline panel). Example: thisComp.layer(3)

layer(name)

Return type: Layer, Light, or Camera.

Argument type: name is a String.

Retrieves the layer by name. Names are matched according to layer name, or source name if there is no layer name. If duplicate names exist, After Effects uses the first (topmost) one in the Timeline panel. Example:

  thisComp.layer("Solid 1")

layer(otherLayer, relIndex)

Return type: Layer, Light, or Camera.

Argument type: otherLayer is a Layer object, and relIndex is a Number.

Retrieves the layer that is relIndex layers above or below otherLayer. For example, thisComp.layer(thisLayer, 1).active returns true if the next layer down in the Timeline panel is active.

marker

Return type: MarkerProperty.

Note:

You cannot access a composition marker by marker number. If you have a project created in a previous version of After Effects that uses composition marker numbers in expressions, you must change those calls to use marker.key(name) instead. Because the default name of a composition marker is a number, converting the reference to use the name is often just a matter of surrounding the number with quotation marks.

marker.key(index)

Return type: MarkerKey.

Argument type: index is a Number.

Returns the MarkerKey object of the marker with the specified index. The index refers to the order of the marker in composition time, not to the name of the marker. For example, this expression returns the time of the first composition marker:

  thisComp.marker.key(1).time

marker.key(name)

Return type: MarkerKey.

Argument type: name is a String.

Returns the MarkerKey object of the marker with the specified name. The name value is the name of the marker, as typed in the comment field in the marker dialog box, for example, marker.key("1"). For a composition marker, the default name is a number. If more than one marker in the composition has the same name, this method returns the marker that occurs first in time (in composition time). The value for a marker key is a String, not a Number. For example, this expression returns the time of the composition marker with the name "0":

  thisComp.marker.key("0").time

marker.nearestKey(t)

Return type: MarkerKey.

Argument type: t is a Number.

Returns the marker that is nearest in time to t. For example, this expression returns the time of the composition marker nearest to the time of 1 second:

  thisComp.marker.nearestKey(1).time

This expression returns the time of the composition marker nearest to the current time:

  thisComp.marker.nearestKey(time).time

marker.numKeys

Return type: Number.

Returns the total number of composition markers in the composition.

numLayers

Return type: Number.

Returns the number of layers in the composition.

activeCamera

Return type: Camera.

Returns the Camera object for the camera through which the composition is rendered at the current frame. This camera is not necessarily the camera through which you are looking in the Composition panel.

width

Return type: Number.

Returns the composition width, in pixels.

Apply the following expression to the Position property of a layer to center the layer in the composition frame:

  [thisComp.width/2, thisComp.height/2]

height

Return type: Number.

Returns the composition height, in pixels.

duration

Return type: Number.

Returns the composition duration, in seconds.

ntscDropFrame

Return type: Boolean.

Returns true if the timecode is in drop-frame format. (After Effects CS5.5and later.)

displayStartTime

Return type: Number.

Returns the composition start time, in seconds.

frameDuration

Return type: Number.

Returns the duration of a frame, in seconds.

shutterAngle

Return type: Number.

Returns the shutter-angle value of the composition, in degrees.

shutterPhase

Return type: Number.

Returns the shutter phase of the composition, in degrees.

bgColor

Return type: Array [4].

Returns the background color of the composition.

pixelAspect

Return type: Number.

Returns the pixel aspect ratio of the composition.

name

Return type: String.

Returns the name of the composition.

Composition marker protected region attribute

The Protected Region option for composition markers can be read with the protectedRegion composition marker attribute.

Footage attributes and methods (expression reference)

To use a footage item from the Project panel as an object in an expression, use the global footage method, as in footage("file_name"). You can also access a footage object using the source attribute on a layer whose source is a footage item.

width

Return type: Number.

Returns the width of the footage item, in pixels.

height

Return type: Number.

Returns the height of the footage item, in pixels.

duration

Return type: Number.

Returns the duration of the footage item, in seconds.

frameDuration

Return type: Number.

Returns the duration of a frame in the footage item, in seconds.

ntscDropFrame

Return type: Boolean.

Returns true if the timecode is in drop-frame format. (After Effects CS5.5 and later.)

pixelAspect

Return type: Number.

Returns the pixel aspect ratio of the footage item.

name

Return type: String.

Returns the name of the footage item as shown in the Project panel.

Layer Sub-objects attributes and methods (expression reference)

source

Return type: Comp or Footage.

Returns the source Comp or source Footage object for the layer. Default time is adjusted to the time in the source. Example: source.layer(1).position

sourceTime(t = time)

Return type: Number.

Returns the layer source corresponding to time t. (After Effects CS5.5 and later.)

sourceRectAtTime(t = time, includeExtents = false)

Return type: JavaScript object with four attributes: [top, left, width, height]. Extents apply only to shape layers, increasing the size of the layer bounds as necessary, and paragraph text layers (After Effects 15.1 and later), where it returns the bounds of the paragraph box. Example: myTextLayer.sourceRectAtTime().width.

effect(name)

Return type: Effect.

Argument type: name is a String.

After Effects finds the effect by its name in the Effect Controls panel. The name can be the default name or a user-defined name. If multiple effects have the same name, the effect closest to the top of the Effect Controls panel is used. Example:

effect("Fast Blur")("Blurriness")

effect(index)

Return type: Effect.

Argument type: index is a Number.

After Effects finds the effect by its index in the Effect Controls panel, starting at 1 and counting from the top.

mask(name)

Return type: Mask.

Argument type: name is a String.

The name can be the default name or a user-defined name. If multiple masks have the same name, the first (topmost) mask is used. Example:

mask("Mask 1")

mask(index)

Return type: Mask.

Argument type: index is a Number.

After Effects finds the mask by its index in the Timeline panel, starting at 1 and counting from the top.

Layer General attributes and methods (expression reference)

width

Return type: Number.

Returns the width of the layer, in pixels. It is the same as source.width.

height

Return type: Number.

Returns the height of the layer, in pixels. It is the same as source.height.

index

Return type: Number.

Returns the index number of the layer in the composition.

parent

Return type: Layer, Light, or Camera.

Returns the parent Layer object of the layer, if it has one. Example: position[0] + parent.width

hasParent

Return type: Boolean.

Returns true if the layer has a parent or false if it doesn’t.

Use the hasParent attribute to determine if a layer has a parent layer. You can use this attribute even if the layer has no parent layer at present. For example, the following expression indicates that the layer to which you apply it wiggles based on the position of the parent. If the layer has no parent, then it wiggles based on its own position. If the layer is given a parent later, then the behavior of the layer changes accordingly:

  idx = index;   if (hasParent) {     idx = parent.index;   }   thisComp.layer(idx).position.wiggle(5,20)

inPoint

Return type: Number.

Returns the In point of the layer, in seconds.

Note:

In general, the value of outPoint is greater than the value of inPoint. However, if a layer is reversed in time, the value of inPoint is greater than the value of outPoint. Similarly, the value of startTime can be greater than the value of inPoint.

outPoint

Return type: Number.

Returns the Out point of the layer, in seconds.

startTime

Return type: Number.

Returns the start time of the layer, in seconds.

hasVideo

Return type: Boolean.

Returns true if the layer has video, or false if it doesn’t.

hasAudio

Return type: Boolean.

Returns true if the layer has audio or false if it doesn’t.

active

Return type: Boolean.

Returns true if the Video switch   is on for the layer and the current time is in the range from the In point of the layer to the Out point of the layer; false otherwise.

enabled

Return type: Boolean.

Returns true if the Video switch   is on for the layer; false otherwise.

audioActive

Return type: Boolean.

Returns true if the Audio switch    is on for the layer and the current time is in the range from the In point of the layer to the Out point of the layer; false otherwise.

sampleImage(point, radius = [.5, .5], postEffect=true, t=time)

Return type: Array [4].

Argument type: point is an Array [2], radius is an Array [2], postEffect is a Boolean, and t is a Number.

Samples the color and alpha channel values of a layer and returns the average alpha-weighted value of the pixels within the specified distance of the point as an array: [red, green, blue, alpha]. If postEffect is true, the sampled values are for the layer after masks and effects on that layer have been rendered; if postEffect is false, the sampled values are for the layer before masks and effects have been rendered. The input value point is in layer space; the point [0,0] is the center of the upper-left pixel in the layer. The input value radius specifies the horizontal and vertical distance from the sample center to the edges of the sampled rectangle. The default value samples one pixel.

Note:

The postEffect parameter refers to effects applied directly to the layer, not to effects applied indirectly, such as with an adjustment layer.

Tip:

Using sampleImage in an expression no longer disables multiprocessing.

This example samples a rectangle 4 pixels wide and 3 pixels high, centered around a point 100 pixels down and to the right of the upper-left corner of the layer:

  thisComp.layer(1).sampleImage([100, 100], [2, 1.5])

Layer Properties attributes and methods (expression reference)

When you add masks, effects, paint, or text to a layer, After Effects adds new properties to the Timeline panel. There are too many of these properties to list here, so use the pick whip to learn the syntax for referring to them in your expressions.

anchorPoint

Return type: Property [2 or 3].

Returns the anchor point value of the layer in the coordinate system of the layer (layer space).

position

Return type: Property [2 or 3].

Returns the position value of the layer, in world space if the layer has no parent. If the layer has a parent, it returns the position value of the layer in the coordinate system of the parent layer (in the layer space of the parent layer).

scale

Return type: Property [2 or 3].

Returns the scale value of the layer, expressed as a percentage.

rotation

Return type: Property.

Returns the rotation value of the layer in degrees. For a 3D layer, it returns the z rotation value in degrees.

opacity

Return type: Property.

Returns the opacity value for the layer, expressed as a percentage.

audioLevels

Return type: Property [2].

Returns the value of the Audio Levels property of the layer in decibels. This value is a 2D value; the first value represents the left audio channel, and the second value represents the right. The value isn't the amplitude of the audio track of the source material. Instead, it's the value of the Audio Levels property, which may be affected by keyframes.

timeRemap

Return type: Property.

Returns the value of the Time Remap property in seconds if it is enabled.

marker.key(index)

Return type: MarkerKey.

Argument type: index is a Number.

Returns the MarkerKey object of the layer marker with the specified index.

marker.key(name)

Return type: MarkerKey.

Argument type: name is a String.

Returns the MarkerKey object of the layer marker with the specified name. The name value is the name of the marker, as typed in the comment field in the marker dialog box, for example, marker.key("ch1"). If more than one marker on the layer has the same name, this method returns the marker that occurs first in time (in layer time). The value for a marker key is a String, not a Number.

This expression on a property ramps the value of the property from 0 to 100 between two markers identified by name:

  m1 = marker.key("Start").time;   m2 = marker.key("End").time;   linear(time, m1, m2, 0, 100);

marker.nearestKey(t)

Return type: MarkerKey.

Argument type: t is a Number.

Returns the layer marker that is nearest in time to t. For example, this expression returns the time of the marker on the layer nearest to the time of 1 second:

  marker.nearestKey(1).time

This expression returns the time of the marker on the layer nearest to the current time:

  marker.nearestKey(time).time

marker.numKeys

Return type: Number.

Returns the total number of markers on the layer.

name

Return type: String.

Returns the name of the layer.

Layer 3D attributes and methods (expression reference)

orientation

Return type: Property [3].

Returns the 3D orientation value, in degrees, for a 3D layer.

rotationX

Return type: Property.

Returns the x rotation value, in degrees, for a 3D layer.

rotationY

Return type: Property.

Returns the y rotation value, in degrees, for a 3D layer.

rotationZ

Return type: Property.

Returns the z rotation value, in degrees, for a 3D layer.

lightTransmission

Return type: Property.

Returns the value of the Light Transmission property for a 3D layer.

castsShadows

Return type: Property.

Returns a value of 1.0 if the layer casts shadows.

acceptsShadows

Return type: Property.

Returns a value of 1.0 if the layer accepts shadows.

acceptsLights

Return type: Property.

Returns a value of 1.0 if the layer accepts lights.

ambient

Return type: Property.

Returns the ambient component value as a percentage.

diffuse

Return type: Property.

Returns the diffuse component value as a percentage.

specular

Return type: Property.

Returns the specular component value as a percentage.

shininess

Return type: Property.

Returns the shininess component value as a percentage.

metal

Return type: Property.

Returns the metal component value as a percentage.

Layer Space Transforms methods (expression reference)

Use layer space transform methods to transform values from one space to another, such as from layer space to world space. The “from” methods transform values from the named space (composition or world) to the layer space. The “to” methods transform values from the layer space to the named space (composition or world). Each transform method takes an optional argument to determine the time at which the transform is computed; however, you can almost always use the current (default) time.

Use “Vec” transform methods when transforming a direction vector, such as the difference between two position values. Use the plain (non-”Vec”) transform methods when transforming a point, such as position. Composition (comp) and world space are the same for 2D layers. For 3D layers, however, composition space is relative to the active camera, and world space is independent of the camera.

toComp(point, t=time)

Return type: Array [2 or 3].

Argument type: point is an Array [2 or 3], and t is a Number.

Transforms a point from layer space to composition space.

fromComp(point, t=time)

Return type: Array [2 or 3].

Argument type: point is an Array [2 or 3], and t is a Number.

Transforms a point from composition space to layer space. The resulting point in a 3D layer may have a nonzero value even though it is in layer space. Example: fromComp(thisComp.layer(2).position)

toWorld(point, t=time)

Return type: Array [2 or 3].

Argument type: point is an Array [2 or 3], and t is a Number.

Transforms a point from layer space to view-independent world space. Example:

  toWorld.effect("Bulge")("Bulge Center")

fromWorld(point, t=time)

Return type: Array [2 or 3].

Argument type: point is an Array [2 or 3], and t is a Number.

Transforms a point from world space to layer space. Example: fromWorld(thisComp.layer(2).position)

Refer to Expression example: Create a bulge between two layers for an example of how this method can be used.

toCompVec(vec, t=time)

Return type: Array [2 or 3].

Argument type: vec is an Array [2 or 3], and t is a Number.

Transforms a vector from layer space to composition space. Example: toCompVec([1,0])

fromCompVec(vec, t=time)

Return type: Array [2 or 3].

Argument type: vec is an Array [2 or 3], and t is a Number.

Transforms a vector from composition space to layer space. Example (2D layer):

  dir=sub(position, thisComp.layer(2).position);   fromCompVec(dir)

toWorldVec(vec, t=time)

Return type: Array [2 or 3].

Argument type: vec is an Array [2 or 3], and t is a Number.

Transforms a vector from layer space to world space. Example: p1 = effect("Eye Bulge 1")("Bulge Center"); p2 = effect("Eye Bulge 2")("Bulge Center");     toWorld(sub(p1, p2))

fromWorldVec(vec, t=time)

Return type: Array [2 or 3].

Argument type: vec is an Array [2 or 3], and t is a Number.

Transforms a vector from world space to layer space. Example: fromWorld(thisComp.layer(2).position)

fromCompToSurface(point, t=time)

Return type: Array [2].

Argument type: point is an Array [2 or 3], and t is a Number.

Projects a point located in composition space to a point on the surface of the layer (zero z-value) at the location where it appears when viewed from the active camera. This method is useful for setting effect control points. Use with 3D layers only.

Camera attributes and methods (expression reference)

Camera objects have the same attributes and methods as Layer objects, except for source, effect, mask, width, height, anchorPoint, scale, opacity, audioLevels, timeRemap, and all the material properties.

pointOfInterest

Return type: Property [3].

Returns the point of interest values of a camera in world space.

zoom

Return type: Property.

Returns the zoom values of a camera in pixels.

Here’s an expression for the Scale property of a layer that maintains the relative size of the layer in frame while changing the z position (depth) of a layer or the Zoom value of a camera:

  cam = thisComp.activeCamera;    distance = length(sub(position, cam.position));    scale * distance / cam.zoom;

depthOfField

Return type: Property.

Returns 1 if the Depth Of Field property of a camera is on or returns 0 if the Depth Of Field property is off.

focusDistance

Return type: Property.

Returns the focus distance value of a camera, in pixels.

aperture

Return type: Property.

Returns the aperture value of a camera, in pixels.

blurLevel

Return type: Property.

Returns the blur level value of a camera as a percentage.

active

Return type: Boolean.

Returns true if the camera is the active camera for the composition at the current time: the Video switch   for the camera layer is on, the current time is in the range from the In point of the camera layer to the Out point of the camera layer, and it's the first (topmost) such camera layer listed in the Timeline panel. Returns false otherwise.

Light attributes and methods (expression reference)

Light objects have the same attributes and methods as Layer objects, except for source, effect, mask, width, height, anchorPoint, scale, opacity, audioLevels, timeRemap, and all the material properties.

pointOfInterest

Return type: Property [3].

Returns the point of interest values for a light in world space.

intensity

Return type: Property.

Returns the intensity values of a light as a percentage.

color

Return type: Property [4].

Returns the color value of a light.

coneAngle

Return type: Property.

Returns the cone angle of a light, in degrees.

coneFeather

Return type: Property.

Returns the cone feather value of a light as a percentage.

shadowDarkness

Return type: Property.

Returns the shadow darkness value of a light as a percentage.

shadowDiffusion

Return type: Property.

Returns the shadow diffusion value of a light, in pixels.

Effect attributes and methods (expression reference)

active

Return type: Boolean.

Returns true if the effect is turned on (the Effect switch    is selected).

param(name)

Return type: Property.

Argument type: name is a String.

Returns a property within an effect. Effect control points are always in layer space. Example:

  effect("Bulge").param("Bulge Height")

param(index)

Return type: Property.

Argument type: index is a Number.

Returns a property within an effect. Effect control points are always in layer space. For example, effect("Bulge").param(4) returns the Bulge Height property.

Mask attributes and methods (expression reference)

Note:

You can link Mask Path properties to other path properties (paths in a shape layer and brush strokes), but the properties are not accessible for direct numerical manipulation through expressions.

maskOpacity

Return type: Property.

Returns the opacity value of a mask as a percentage.

maskFeather

Return type: Property.

Returns the feather value of a mask, in pixels.

maskExpansion

Return type: Property.

Returns the expansion value of a mask, in pixels.

invert

Return type: Boolean.

Returns true if the mask is inverted or false if it is not.

Property attributes and methods (expression reference)

value

Return type: Number, Array, or String.

Returns the value of a property at the current time.

valueAtTime(t)

Return type: Number or Array.

Argument type: t is a Number.

Returns the value of a property at the specified time, in seconds.

For example, to have a property value for each frame chosen randomly from a set of four values, set your four values as keyframes at 0, 1, 2, and 3 seconds, and then apply the following expression to the property:

  valueAtTime(random(4))

velocity

Return type: Number or Array.

Returns the temporal velocity value at the current time. For spatial properties, such as Position, it returns the tangent vector value. The result is the same dimension as the property.

velocityAtTime(t)

Return type: Number or Array.

Argument type: t is a Number.

Returns the temporal velocity value at the specified time.

speed

Return type: Number.

Returns a 1D, positive speed value equal to the speed at which the property is changing at the default time. This element can be used only for spatial properties.

speedAtTime(t)

Return type: Number.

Argument type: t is a Number.

Returns the spatial speed value at the specified time.

wiggle(freq, amp, octaves=1, amp_mult=.5, t=time)

Return type: Number or Array.

Argument type: freq, amp, octaves, amp_mult, and t are Numbers.

Randomly shakes (wiggles) the value of the property.

freq value is the frequency in wiggles per second.

amp value is the amplitude in units of the property to which it is applied.

octaves is the number of octaves of noise to add together. This value controls how much detail is in the wiggle. Make this value higher than the default of 1 to include higher frequencies or lower to include amplitude harmonics in the wiggle.

amp_mult is the amount that amp is multiplied by for each octave. This value controls how fast the harmonics drop off. The default is 0.5; make it closer to 1 to have the harmonics added at the same amplitude as the base frequency, or closer to 0 to add in less detail.

t is the base start time. This value defaults to the current time. Use this parameter if you want the output to be a wiggle of the property value sampled at a different time.

Example: position.wiggle(5, 20, 3, .5) produces about 5 wiggles per second with an average size of about 20 pixels. In addition to the main wiggle, two more levels of detailed wiggles occur with a frequency of 10 and 20 wiggles per second and sizes of 10 and 5 pixels, respectively.

This example, on a two-dimensional property such as Scale, wiggles both dimensions by the same amount:

  v = wiggle(5, 10);   [v[0], v[0]]

This example, on a two-dimensional property, wiggles only along the y-axis:

  freq = 3;   amp = 50;   w = wiggle(freq,amp);   [value[0],w[1]];

temporalWiggle(freq, amp, octaves=1, amp_mult=.5, t=time)

Return type: Number or Array.

Argument type: freq, amp, octaves, amp_mult, and t are Numbers.

Samples the property at a wiggled time. The freq value is the frequency in wiggles per second, amp is the amplitude in units of the property to which it is applied, octaves is the number of octaves of noise to add together, amp_mult is the amount that amp is multiplied by for each octave, and t is the base start time. For this function to be meaningful, the property it samples must be animated, because the function alters only the time of sampling, not the value. Example: scale.temporalWiggle(5, .2)

smooth(width=.2, samples=5, t=time)

Return type: Number or Array.

Argument type: width, samples, and t are Numbers.

Smooths the property values over time, converting large, brief deviations in the value to smaller, more evenly distributed deviations. This smoothing is accomplished by applying a box filter to the value of the property at the specified time. The width value is the range of time (in seconds) over which the filter is averaged. The samples value is the number of discrete samples evenly spaced over time; use a larger value for greater smoothness (but decreased performance). Generally, you’ll want samples to be an odd number so that the value at the current time is included in the average. Example: position.smooth(.1, 5)

loopIn(type="cycle", numKeyframes=0)

Return type: Number or Array.

Loops a segment of time that is measured from the first keyframe on the layer forward toward the Out point of the layer. The loop plays from the In point of the layer. The numKeyframes value determines what segment is looped: The segment looped is the portion of the layer from the first keyframe to the numKeyframes+1 keyframe. For example, loopIn("cycle", 3) loops the segment bounded by the first and fourth keyframes. The default value of 0 means that all keyframes loop.

You can use keyframe-looping methods to repeat a series of keyframes. You can use these methods on most properties. Exceptions include properties that can’t be expressed by simple numeric values in the Timeline panel, such as the Source Text property, path shape properties, and the Histogram property for the Levels effect. Keyframes or duration values that are too large are clipped to the maximum allowable value. Values that are too small result in a constant loop.

loop type

result

cycle

(default) Repeats the specified segment.

pingpong

Repeats the specified segment, alternating between forward and backward.

offset

Repeats the specified segment, but offsets each cycle by the difference in the value of the property at the start and end of the segment, multiplied by the number of times the segment has looped.

continue

Does not repeat the specified segment, but continues to animate a property based on the velocity at the first or last keyframe. For example, if the last keyframe of a Scale property of a layer is 100%, the layer continues to scale from 100% to the Out point, instead of looping directly back to the Out point. This type does not accept a keyframes or duration argument.

loopOut(type="cycle", numKeyframes=0)

Return type: Number or Array.

Loops a segment of time that is measured from the last keyframe on the layer back toward the In point of the layer. The loop plays until the Out point of the layer. The specified number of keyframes determines the segment to loop. The numKeyframes value sets the number of keyframe segments to loop; the specified range is measured backward from the last keyframe. For example, loopOut("cycle", 1) loops the segment bounded by the last keyframe and second-to-last keyframe. The default value of 0 means that all keyframes loop. See the entry for loopIn for more information.

loopInDuration(type="cycle", duration=0)

Return type: Number or Array.

Loops a segment of time that is measured from the first keyframe on the layer forward toward the Out point of the layer. The loop plays from the In point of the layer. Specified duration determines the segment to loop. The duration value sets the number of composition seconds in a segment to loop; the specified range is measured from the first keyframe. For example, loopInDuration("cycle",1) loops the first second of the entire animation. The default of 0 means that the segment to loop begins at the layer Out point. See the entry for loopIn for more information.

loopOutDuration(type="cycle", duration=0)

Return type: Number or Array.

Loops a segment of time that is measured from the last keyframe on the layer back toward the In point of the layer. The loop plays until the Out point of the layer. Specified duration determines the segmetn to loop. The duration value sets the number of composition seconds in a segment to loop; the specified range is measured backward from the last keyframe. For example, loopOutDuration("cycle", 1) loops the last second of the entire animation. The default of 0 means that the segment to loop begins at the layer In point. See the entry for loopIn for more information.

key(index)

Return type: Key or MarkerKey.

Argument type: index is a Number.

Returns the Key or MarkerKey object by number. For example, key(1) returns the first keyframe.

key(markerName)

Return type: MarkerKey.

Argument type: markerName is a String.

Returns the MarkerKey object with this name. Use only on marker properties.

nearestKey(t)

Return type: Key or MarkerKey.

Returns the Key or MarkerKey object nearest to a designated time.

numKeys

Return type: Number.

Returns the number of keyframes on a property. Returns the number of markers on a marker property.

Note:

If you use the Separate Dimensions command to separate the dimensions of the Position property into individual components, the number of keyframes changes, so the value returned by this method changes.

propertyGroup(countUp = 1)

Return type: Group.

Returns a group of properties relative to the property on which the expression is written. For example, if you add the propertyGroup(1) expression to the Rotation property of a brush stroke, the expression targets the Transform property group, which contains the Rotation property. If you add propertyGroup(2) instead, the expression targets the Brush property group. This method lets you establish name-independent relationships in the property hierarchy. This method is especially useful when duplicating properties that contain expressions.

The numProperties method for propertyGroup returns the number of properties in the property group.

This example returns the number of properties in the group that contains the property on which the expression is written:

  thisProperty.propertyGroup(1).numProperties

propertyIndex

Return type: Number.

Returns the index of a property relative to other properties in its property group, including property groups within masks, effects, text animators, selectors, shapes, trackers, and track points.

name

Return type: String.

Returns the name of the property or property group.

Project properties (expression reference)

Expression method:

  • thisProject object thisProject - Represents the project which contains the expression.

Type:

Project object; read-only

  • Project fullPath attribute thisProject.fullPath - The platform-specific absolute file path, including the project file name. If the project has not been saved, it returns an empty string.

Type: String; read-only.

  • Project bitsPerChannel attribute thisProject.bitsPerChannel - The color depth of the project in bits per channel (bpc), as set in Project Settings > Color Management. They are one of 8, 16, or 32. Equivalent to the scripting project attribute app.project.bitsPerChannel.

Type Number; read-only.

  • Project linearBlending attribute thisProject.linearBlending - The state of the Blend Colors Using 1.0 gamma option in Project Settings > Color Management. Equivalent to the scripting project attribute app.project.linearBlending.

Type: Boolean; read-only.

Key attributes and methods (expression reference)

When you access a Key object, you can get time, index, and value properties from it. For example, the following expression gives you the value of the third Position keyframe: position.key(3).value.

The following expression, when written on an Opacity property with keyframes, ignores the keyframe values and uses only the placement of the keyframes in time to determine where a flash should occur:   d = Math.abs(time - nearestKey(time).time);   easeOut(d, 0, .1, 100, 0)

  d = Math.abs(time - nearestKey(time).time); 
  easeOut(d, 0, .1, 100, 0)

value

Return type: Number or Array.

Returns the value of the keyframe.

time

Return type: Number.

Returns the time of the keyframe.

index

Return type: Number.

Returns the index of the keyframe.

MarkerKey attributes (expression reference)

You can access values for composition markers and layer markers using the same methods. Access layer markers through the thisLayer.marker object; access composition markers through the thisComp.marker object.

For the purpose of expressions, markers are a special type of Key object, so you can use methods such as nearestKey(time) to access markers, and markers also have time and index attributes. The index attribute is not the number (name) of the marker; it is the keyframe index number, representing the order of the marker in the time ruler.

Expressions have access to all the values for a marker that you can set in the Composition Marker or Layer Marker dialog box. This expression on the Source Text property of a text layer displays the time, duration, index, comment (name), chapter, URL, frame target, and cue point name for the layer marker nearest the current time and whether the marker is for an event cue point:

  m = thisLayer.marker.nearestKey(time);  
  s = "time:" + timeToCurrentFormat(m.time) + "\r" +  
      "duration: " + m.duration + "\r" +  
      "key index: " + m.index + "\r" +  
      "comment:" + m.comment + "\r" +  
      "chapter:" + m.chapter + "\r" +  
      "URL:" + m.url + "\r" +  
      "frame target: " + m.frameTarget + "\r" +  
      "cue point name: " + m.cuePointName + "\r" +  
      "Event cue point? " + m.eventCuePoint + "\r";  
  for (param in m.parameters){  
       s += "parameter: " + param + " value: " + m.parameters[param] + "\r";  
  } 
  s

Because the XMP metadata in a footage item can be converted into layer markers for a layer based on that item, expressions can interact with XMP metadata. For information, refer to XMP metadata in After Effects.

duration

Return type: Number.

Duration, in seconds, of marker.

comment

Return type: String.

Contents of Comment field in marker dialog box.

chapter

Return type: String.

Contents of Chapter field in marker dialog box.

url

Return type: String.

Contents of URL field in marker dialog box.

frameTarget

Return type: String.

Contents of Frame Target field in marker dialog box.

eventCuePoint

Return type: Boolean.

Setting for cue point type in marker dialog box. True for Event; false for Navigation.

cuePointName

Return type: String.

Contents of cue point Name field in marker dialog box.

parameters

Return type: associative array of String values.

Contents of Parameter Name and Parameter Value fields in marker dialog box.

For example, if you have a parameter named “background color”, then you can use the following expression to access its value at the nearest marker:

  thisComp.marker.nearestKey(time).parameters["background color"]

MarkerValue.protectedRegion (expression reference)

Expression method:

thisComp.marker.key(index).protectedRegion

Description:

When true, the composition marker behaves as a protected region.

Type:

Boolean; read only.

Expression access to paths points on shapes, masks, and brush strokes (expression reference)

You can use expressions to read and write the x and y coordinates of path points, or vertices, for:

  • Layer masks
  • Bezier shapes
  • Brush strokes on the Paint and Roto Brush & Refine Edge effects.

Expression methods:

  • Path points() method: {pathProperty}.points(t = time) Get the x,y coordinates of all points on a path. Coordinates for layer mask path points are relative to the layer's origin in its upper-left-hand corner. Coordinates for Bezier shape path points are relative to the anchor point of the path's shape group, for example, Transform: Shape 1 > Anchor Point. The coordinates for brush stroke path points are relative to the start of the stroke; the first point is [0,0]. Optionally specify the time at which to sample the path. You can pass this method into the createPath() method for the points parameter when duplicating a path.

Parameters:

t

Number, optional. The composition time (in seconds) at which to sample the path. Default is time (the current time).

Returns:

Array of number pair arrays, rounded to the fourth decimal place.

  • Path inTangents() method: {pathProperty}.inTangents(t = time) Get the x,y coordinates of the incoming tangent handle for all points on a path. Tangent coordinate values are offset relative to the parent point's coordinates. i.e., The value [0,0] creates no curvature at the incoming tangent. This method can be passed into the createPath() method for the inTangents parameter when duplicating a path. Optionally specify the time at which to sample the path.

Parameters:

t

Number, optional. The composition time (in seconds) at which to sample the path. Default is time (the current time).

Returns:

Array of number pair arrays, rounded to the fourth decimal place.

  • Path outTangents() method: {pathProperty}.outTangents(t = time) Get the x,y coordinates of the outgoing tangent handle for all points on a path. Tangent coordinate values are offset relative to the parent point's coordinates - The value [0,0] creates no curvature at the outgoing tangent. This method can be passed into the createPath() method for the outTangents parameter when duplicating a path. Optionally specify the time at which to sample the path.

Parameters:

t

Number, optional. The composition time (in seconds) at which to sample the path. Default is time (the current time).

Returns:

Array of number pair arrays, rounded to the fourth decimal place.

  • Path isClosed() method{pathProperty}.isClosed()Determines if the path is open or closed. Returns true if the path is closed, false if the path is open. This method can be passed into the createPath() method for the is_closed parameter when duplicating a path.

Parameters:

None

Returns:

Boolean

  • Path pointOnPath() method {pathProperty}.pointOnPath(percentage = 0.5, t = time)Get the x,y coordinates of an arbitrary point along a path.The point is expressed as a percentage of the arc-length of the path. 0% is the first point and 100% is the last point. When the path is closed, 0% and 100% will return the same coordinates. Percentage of arc-length is used to ensure uniform speed along the path. Other than 0% and 100%, percentages do not necessarily correlate with the Bezier points on the path - For a path with three points, the second point will not necessarily be at 50%. This also means that for an open path and closed path with identical points, the percentage along the open path will not return the same coordinates as the closed path due to the additional length of the closed path. Optionally specify the time at which to sample the path.

Parameters:

percentage

Number between 0 and 1, optional. The percentage along the arc-length of the path to sample. Values smaller than 0 and larger than 1 are clipped. Default is 0.5.

t

Number, optional. The composition time (in seconds) at which to sample the path. Default is time (the current time).

Returns:

A number pair array.

  • Path tangentOnPath() method {pathProperty}.tangentOnPath(percentage = 0.5, t = time) Get the calculated x,y coordinates of the outgoing tangent handle for an arbitrary point along a path. Tangent coordinate values are offset relative to the parent point's coordinates - The value [0,0] creates no curvature at the outgoing tangent. The incoming tangent handle is the inverse of this value (multiply the x,y coordinates by -1). The tangent's parent point is expressed as a percentage of the arc-length of the path. The coordinates returned by tangentOnPath() are calcuated from it's parent point and will differ from those returned by outTangents() if a user-defined point also exists at that arc-length pecentage. The linear distance between the parent point's coordinates and tangentOnPath() coordinates will always be 1. You can multiply the returned coordinates to create a longer tangent, ex. (myPath.tangentOnPath() * 100). Optionally specify the time at which to sample the path.

Parameters:

percentage

Number between 0 and 1, optional. The percentage along the arc-length of the path to sample. Values smaller than 0 and larger than 1 are clipped. Default is 0.5.

t

Number, optional. The composition time (in seconds) at which to sample the path. Default is time (the current time).

Returns:

A number pair array.

  • Path normalOnPath() method {pathProperty}.normalOnPath(percentage = 0.5, t = time) Get the calculated x,y coordinates of the normal for an arbitrary point along a path. Coordinate values of normals are offset relative to the parent point's coordinates - The value [0,0] is the same as the parent point. The normal's parent point is expressed as a percentage of the arc-length of the path. Read the description of the pointOnPath() method for details about arc-length percentage. The coordinates returned by normalOnPath() are calculated from its parent point. The linear distance between the parent point's coordinates and normalOnPath() coordinates will always be 1. You can multiply the returned coordinates to create a longer normal, for example, (myPath.normalOnPath() * 100). Optionally specify the time at which to sample the path.

Parameters:

percentage

Number between 0 and 1, optional. The percentage along the arc-length of the path to sample. Values smaller than 0 and larger than 1 are clipped. Default is 0.5.

t

Number, optional. The composition time (in seconds) at which to sample the path. Default is time (the current time).

Returns:

A number pair array.

  • Path createPath() method {pathProperty}.createPath(points = [[0,0], [100,0], [100,100], [0,100]], inTangents = [], outTangents = [], is_closed = true) Creates a path object from a set of points and tangents. The points are defined by an array of number pair arrays representing their x,y coordinates. The array length must be at least 1, and can be of any greater length. The incoming and outgoing tangent handles of the points are defined by an array of number pair arrays representing their x,y offset coordinates. The length of the tangent arrays must be exactly the same as the points paramater. Tangent coordinate values are offset relative to the parent point's coordinates - The value [0,0] creates no curvature at the incoming tangent. The points(), inTangents()outTangents(), and isClosed() methods of a path can be passed into the points, inTangents, outTangents, and is_closed parameters to duplicate a path. The points and tangents of the same path can be passed into createPath() with modifications to generate a different result. For example, the following expression will remove curves from Mask 1 by not passing the inTangents or outTangents parameters:

myMask = mask("Mask 1").path;
myMask.createPath(myMask.points());

The following example passes the points and tangents of Mask 1 and converts it to an open path by setting is_closed to false:

myMask = mask("Mask 1").path;
myMask.createPath(myMask.points(), myMask.inTangents(), myMask.outTangents(), false);

 

points

An array of length 1 or greater containing number pair arrays representing the [x,y] coordinates of the path points. Required unless no parameters are passed (i.e., createPath()). Default is [[0,0], [100,0], [100,100], [0,100]].

is_closed

Boolean, optional. Determines if the mask is closed. If true, the last point will be connected to the first point. Default is true.

inTangents

An array containing number pair arrays representing the [x,y] offset coordinates of the outgoing tangent handles to the path points. Required unless no parameters are passed (i.e., createPath()). The array length must be the same as points, or you can pass an empty array ([]), which will assume the same length as points and [0,0] for all tangents. Default is an empty array.

outTangents

An array containing number pair arrays representing the [x,y] offset coordinates of the incoming tangent handles to the path points. Required unless no parameters are passed (i.e., createPath()). The array length must be the same as points, or you can pass an empty array ([]), which will assume the same length as points and [0,0] for all tangents. Default is an empty array.

Returns:

A path object.

Examples:

  • Example 1

The example writes the list of point and tangent coordinates from Path 1 of Shape 1 on layer Shape Layer 1, at time=0, into a string. Apply this to the source text property of a text layer for a readout of the coordinates and incoming and outgoing tangents of the shape.

pointsList = "";
sampleTime = 0;

myShape = thisComp.layer("Shape Layer 1").content("Shape 1").content("Path 1").path;

for (i = 0; i < myShape.points(sampleTime).length; i++) {
    pointsList += "c: " + myShape.points(sampleTime)[i].toString() + "  i: " + myShape.inTangents(sampleTime)[i].toString() + " o: " + myShape.outTangents(sampleTime)[i].toString() + "\n";
}

pointsList;

  • Example 2

The example reads the coordinates of the first vertex of Mask 1 on Dark Gray Solid 1 and converts them to composition coordinates. Apply this to a 2D point control of an effect, such as Write-on or CC Particle Systems II, to make the effect trace or track the first point of an animated mask. Duplicate the effect and change the path points index value ([0]) to trace or track the other points of the mask.

myLayer = thisComp.layer("Dark Gray Solid 1");
myLayer.toComp(myLayer.mask("Mask 1").maskPath.points()[0]);

Data-driven animation (expression reference)

Expression methods:

  • Footage sourceText attribute {footageItem}.sourceText Returns the contents of a .JSON file as a string. The eval() method can be used to convert the string to an array of sourceData objects, identical to the results of the sourceData attribute, from which the individual data streams can be referenced as hierarchal attributes of the data. For example: 

var myData = eval(footage("sample.json").sourceText);

myData.sampleValue;

Type:

String, the contents of the .JSON file; read-only.

  • Footage sourceData attribute {footageItem}.sourceData Returns the data of a .JSON file as an array of sourceData objects. The structure of the .JSON file will determine the size and complexity of the array. Individual data streams can be referenced as hierarchal attributes of the data. For example, given a data stream named Color, the following will return the value of Color from the first data object: footage("sample.json").sourceData[0].Color

Typical use is to assign a .JSON file's sourceData to a variable, and then reference the desired data stream. For example:

var myData = footage("sample.json").sourceData;

myData[0].Color;

Type:

An array of sourceData objects; read-only.

  • Footage dataValue() method {footageItem}.dataValue(dataPath) Returns the value of specificed static or dynamic data stream in a .mgJSON file. Accepts a single array value to define the path in the hierarchy to the desired data stream. For example:

footage("sample.mgjson").dataValue([0]) returns data of the first child.

footage("sample.mgjson").dataValue([1][0]) returns data of the first child in the second group.

Parameters:

dataPath 

Array, required. The path in the hierarchy to a static or dynamic data stream.

Returns:

The value of the data stream.

  • Footage dataKeyCount() method {footageItem}.dataKeyCount(dataPath)Returns the number of samples in a specificed dynamic data stream in a .mgJSON file.Accepts a single array value to define the path in the hierarchy to the desired dynamic data stream. 

For example:

  • footage("sample.mgjson").dataKeyCount([0]) returns the count of samples for the first child
  • footage("sample.mgjson").dataKeyCount([1][0]) returns the count of samples for the second group

Parameters:

dataPath 

Array, required. The path in the hierarchy to a static or dynamic data stream.

Returns:

The number of samples in the dynamic data stream.

  • Footage dataKeyTimes() method {footageItem}.dataKeyTimes(dataPath, t0 = startTime, t1=endTime)Returns the time in seconds for the samples of a specificed dynamic data stream in a .mgJSON file. Optionally specify the time span from which to return samples. By default the time for all samples between startTime and endTime in the dynamic data stream are returned, as defined by the data stream's samplesTemporalExtent property in the .mgJSON file. Accepts a single array value to define the path in the hierarchy to the desired dynamic data stream. 

The following example returns the times of samples between 1 second and 3 seconds for the first child:

footage("sample.mgjson").dataKeyTimes([0], 1, 3)

Parameters:

dataPath

Array, required. The path in the hierarchy to a dynamic data stream.

t0

Number, optional. The start time, in seconds, of the span from which to return samples. Defaults to startTime.

t1

Number, optional. The end time, in seconds, of the span from which to return samples. Defaults to endTime.

Returns:

Array of numbers representing the sample times.

  • Footage dataKeyValues() method {footageItem}.dataKeyValues(dataPath, t0 = startTime, t1=endTime)Returns the values for the samples of a specificed dynamic data stream in a .mgJSON file. Optionally specify the time span from which to return samples. By default the time for all samples between startTime and endTime in the dynamic data stream are returned, as defined by the data stream's samplesTemporalExtent property in the .mgJSON file. Accepts a single array value to define the path in the hierarchy to the desired dynamic data stream. 

For example:

footage("sample.mgjson").dataKeyValues([0], 1, 3) returns the values of samples between 1 second and 3 seconds for the first child.

Parameters:

dataPath

Array, required. The path in the hierarchy to a dynamic data stream.

t0

Number, optional. The start time, in seconds, of the span from which to return samples. Defaults to startTime.

t1

Number, optional. The end time, in seconds, of the span from which to return samples. Defaults to endTime.

Returns:

Array of numbers representing the sample values.

Hex to RGB color conversion method (expression reference)

This color conversion method, hexToRgb(), converts hexadecimal color values, for example, #FF00FF to RGBA color values. This can be useful to link color parameters to color values represented as hex strings in JSON or CSV/TSV data sources.

Expression method:

hexToRgb(hexString) Converts a color in hex triplet space to RGB, or in hex quartet space to RGBA space. For hex triplets, alpha defaults to 1.0.

Parameters:

hexString

String representing an hex triplet (6 digits, no alpha channel) or quartet (8 digits, includes alpha channel) containing only numerals or characters A–F. Optional leading characters 0x, 0X, or # are ignored. Characters beyond 8 digits are ignored.

Returns:

RGBA color value array.

Examples:

Any of the following will return [1.0, 0.0, 1.0, 1.0]:

  • hexToRgb("FF00FF")
  • hexToRgb("#FF00FF")
  • hexToRgb("0xFF00FF")
  • hexToRgb("0XFF00FFFF") Note: 8-digit hex quartet; last two digits set alpha to 1.0.

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online