general
Layer General
Section titled “Layer General”thisLayer
On this page, we’re going to use thisLayer
as a sample on how to call these items, however note that any method that returns a Layer will work.
Attributes
Section titled “Attributes”Layer.active
Section titled “Layer.active”thisLayer.active
Description
Section titled “Description”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.
Boolean
Layer.audioActive
Section titled “Layer.audioActive”thisLayer.audioActive
Description
Section titled “Description”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.
Boolean
Layer.enabled
Section titled “Layer.enabled”thisLayer.enabled
Description
Section titled “Description”Whether the layer is enabled.
Boolean. true
if the Video switch is on for the layer; false
otherwise.
Layer.hasAudio
Section titled “Layer.hasAudio”thisLayer.hasAudio
Description
Section titled “Description”Whether the layer has audio.
Boolean. true
if the layer has audio or false
if it doesn’t.
Layer.hasParent
Section titled “Layer.hasParent”thisLayer.hasParent
Description
Section titled “Description”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.
Boolean. true
if the layer has a parent, false
if it doesn’t.
Example
Section titled “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)
Layer.hasVideo
Section titled “Layer.hasVideo”thisLayer.hasVideo
Description
Section titled “Description”Whether the layer has video.
Boolean. true
if the layer has audio or false
if it doesn’t.
Layer.height
Section titled “Layer.height”thisLayer.height
Description
Section titled “Description”Returns the height of the layer, in pixels.
If the layer has a source, this is the same as either the source comp height or the source footage height (as applicable).
Number
Layer.index
Section titled “Layer.index”thisLayer.index
Description
Section titled “Description”Returns the index number of the layer in the composition.
Number
Layer.inPoint
Section titled “Layer.inPoint”thisLayer.inPoint
Description
Section titled “Description”Returns the In point of the layer, in seconds.
Number
Layer.outPoint
Section titled “Layer.outPoint”thisLayer.outPoint
Description
Section titled “Description”Returns the Out point of the layer, in seconds.
Number
Layer.parent
Section titled “Layer.parent”thisLayer.parent
Description
Section titled “Description”Returns the parent Layer object of the layer, if it has one.
You can check whether a layer has a parent with the Layer.hasParent
attribute.
Layer, Light, or Camera object
Example
Section titled “Example”position[0] + parent.width
Layer.startTime
Section titled “Layer.startTime”thisLayer.startTime
Description
Section titled “Description”Returns the start time of the layer, in seconds.
Number
Layer.width
Section titled “Layer.width”thisLayer.width
Description
Section titled “Description”Returns the width of the layer, in pixels.
If the layer has a source, this is the same as either the source comp width or the source footage width (as applicable).
Number
Methods
Section titled “Methods”Layer.sampleImage()
Section titled “Layer.sampleImage()”thisLayer.sampleImage(point[, radius=[0.5, 0.5]][, postEffect=true][, t=time])
Description
Section titled “Description”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]
.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
point | 2-dimensional Number array | Required. The point at which to sample, im layer space. The point [0, 0] is the center of the upper-left pixel in the layer. |
radius | 2-dimensional Number array | Optional. Specifies the horizontal and vertical distance from the sample center to the edges of the sampled rectangle. The default value samples one pixel. Defaults to [0.5, 0.5] . |
postEffect | Boolean | Optional. If true , to sample the values after layer masks and effects directly applied to the layer have been rendered. If false , sample values before layer masks and effects. Defaults to true . |
t | Number | Optional. Defaults to time . |
Array (4-dimensional)
Examples
Section titled “Examples”This 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])