Global functions
These globally available functions that are specific to After Effects. Any JavaScript object or function can call these functions, which allow you to display text in a small (3-line) area of the Info panel, and to convert numeric time values to and from string values.
Additional global functions for standard user I/O (alert, confirm, and prompt) and static functions for file I/O, are defined by ExtendScript; for detailed reference information, see the JavaScript Tools Guide (available from the ExtendScript Toolkit’s Help menu).
| Global Function | Description |
|---|---|
| clearOutput() | Clears text from the Info panel. |
| currentFormatToTime() | Converts string time value to a numeric time value. |
| timeToCurrentFormat() | Converts a numeric time value to a string time value. |
| write() | Writes text to the Info panel, with no line break added. |
| writeLn() | Writes text to the Info panel, adding a line break at the end. |
| isValid() | When true, the specified object exists. |
clearOutput()
global function
Description: Clears the output in the Info panel. Parameters: None. Returns: Nothing.
currentFormatToTime()
global function
Syntax: currentFormatToTime(formattedTime, fps, isDuration)
Description: Converts a formatted string for a frame time value to a number of seconds, given a specified frame rate. For example, if the formatted frame time value is 0:00:12 (the exact string format is determined by a project setting), and the frame rate is 24 fps, the time would be 0.5 seconds (12/24). If the frame rate is 30 fps, the time would be 0.4 seconds (12/30). If the time is a duration, the frames are counted from 0. Otherwise, the frames are counted from the project’s starting frame (see “Project displayStartFrame attribute” on page 117).
Parameters: * formattedTime The frame time value, a string specifying a number of frames in the project’s current time display format. | * fps The frames-per-second, a floating-point value. * isDuration Optional When true, the time is a duration (measured from frame 0). When false (the default), the time is measured from the project’s starting frame. |
Returns: Floating-point value, the number of seconds.
isValid()
global function
Syntax: isValid(obj) Description: Determines if the specified After Effects object (e.g., composition, layer, mask, etc.) still exists. Some operations, such as the PropertyBase moveTo() method, might invalidate existing variable assignments to related objects. This function allows you to test whether those assignments are still valid before attempting to access them.
Parameters: * obj The After Effects object to check for validity. Returns: Boolean
Example:
var layer = app.project.activeItem.layer(1); // assume layer has three masks
alert(isValid(layer)); // displays “true”
var mask1 = layer.mask(1);
var mask2 = layer.mask(2);
var mask3 = layer.mask(3);
mask3.moveTo(1); // move the third mask to the top of the mask stack
alert(isValid(mask1)); // displays “false”; mask2 and mask3 do as well
timeToCurrentFormat() global function
Syntax: timeToCurrentFormat(time, fps, isDuration)
Description
Converts a numeric time value (a number of seconds) to a frame time value; that is, a formatted string that shows which frame corresponds to that time, at the specified rate. For example, if the time is 0.5 seconds, and the frame rate is 24 fps, the frame would be 0:00:12 (when the project is set to display as timecode). If the frame rate is 30 fps, the frame would be 0:00:15. The format of the timecode string is determined by a project setting. If the time is a duration, the frames are counted from 0. Otherwise, the frames are counted from the project’s starting frame (see “Project displayStartFrame attribute” on page 117).
Parameters * isDuration Optional. When true, the time is a duration (measured from frame 0). When false (the default), the time is measured from the project’s starting frame. * obj The After Effects object to check for validity. time The number of seconds, a floating-point value. fps The frames-per-second, a floating-point value.
Returns: String in the project’s current time display format.
write() global function
Syntax: write(text)
Description: Writes output to the Info panel, with no line break added.
Parameters: * text The string to display. Truncated if too long for the Info panel.
Returns: Nothing.
Example:
write("This text appears in Info panel ");
write("with more on same line.");
writeLn() global function
Syntax: writeLn(text) Description: Writes output to the Info panel and adds a line break at the end.
Parameters * text The string to display. Truncated if too long for the Info panel.
Returns: Nothing.
Example
writeln("This text appears on first line");
writeln("This text appears on second line");