Yes, absolutely! You can display the value of almost any property from any layer (including properties related to shapes within a Shape Layer) inside a Text Layer using Expressions.
The key is to link the Source Text property of the Text Layer to the specific shape property you want to display using an expression.
Here's how you do it and some examples depending on what "Shape variable" you mean:
General Steps:
- Select your Text Layer in the Timeline.
- Twirl down its properties until you see Text > Source Text.
- Alt+Click (Windows) or Option+Click (Mac) on the stopwatch icon next to Source Text. This enables expressions for that property and opens the expression editor field.
- Use the Expression Pick Whip:
- Click and drag the little spiral icon (the pick whip) from the Source Text expression field onto the specific property you want to display from the other layer (e.g., the Size of a Rectangle Path within a Shape Layer).
- After Effects will automatically write the basic code to reference that property.
- Modify the Expression (if needed): The referenced property might not be a simple text string. You'll often need to format it or extract specific parts.
Examples:
Let's assume you have a Shape Layer named "My Shape Layer" containing a Rectangle named "Rectangle 1".
Example 1: Displaying the Size of a Rectangle Path
-
Target Property: My Shape Layer > Contents > Rectangle 1 > Rectangle Path 1 > Size
-
Expression on the Text Layer's Source Text:
// Use the pick whip to target the 'Size' property first
// It will generate something like:
// temp = thisComp.layer("My Shape Layer").content("Rectangle 1").content("Rectangle Path 1").size;
// Then modify it to display nicely:
var shapeLayer = thisComp.layer("My Shape Layer");
var rectSize = shapeLayer.content("Rectangle 1").content("Rectangle Path 1").size;
var width = Math.round(rectSize[0]); // Get the width (index 0) and round it
var height = Math.round(rectSize[1]); // Get the height (index 1) and round it
"Rectangle Size: " + width + " x " + height; // Combine into a string
Example 2: Displaying the Position of a Shape Group's Transform
-
Target Property: My Shape Layer > Contents > Rectangle 1 > Transform > Position
-
Expression on the Text Layer's Source Text:
var shapeLayer = thisComp.layer("My Shape Layer");
var shapePosition = shapeLayer.content("Rectangle 1").transform.position;
var xPos = Math.round(shapePosition[0]);
var yPos = Math.round(shapePosition[1]);
"Shape Position: [" + xPos + ", " + yPos + "]";
Example 3: Displaying the Number of Vertices in a Path
-
Target Property: My Shape Layer > Contents > Shape 1 > Path 1 > Path (Assuming 'Shape 1' contains a Bezier path)
-
Expression on the Text Layer's Source Text:
var shapeLayer = thisComp.layer("My Shape Layer");
var pathProperty = shapeLayer.content("Shape 1").content("Path 1").path;
// We need to access the points at the current time
var pathData = pathProperty.value; // or pathProperty.valueAtTime(time);
// Check if the pathData object and its vertices array exist
if (pathData && pathData.vertices) {
"Vertex Count: " + pathData.vertices.length;
} else {
"Path data not available"; // Fallback text
}
(Note: Accessing path data can sometimes be tricky depending on whether it's animated or parametric)
Example 4: Displaying the Layer's own Width/Height (if that's what you mean by "Shape")
-
Target Property: The width or height of the layer itself.
-
Expression on the Text Layer's Source Text:
var targetLayer = thisComp.layer("My Shape Layer"); // Or any other layer
"Layer Dimensions: " + Math.round(targetLayer.width) + " x " + Math.round(targetLayer.height);
Key Things to Remember:
- Exact Names: You need the exact names of the layers and properties within the
content() hierarchy. The pick whip is your best friend here.
- Data Types: Properties return different data types (Numbers, Arrays [like Size, Position], Strings, Shape objects). You often need to convert or format these into a single string for the Source Text property.
- Arrays: Access array elements using index numbers (e.g.,
size[0] for width, position[1] for y).
- Formatting: Use standard JavaScript string concatenation (
+) and functions like Math.round() to make the output readable.
So, yes, it's very possible and a common use case for expressions in After Effects! Just pinpoint the exact property you want to display and use the pick whip on the Text Layer's Source Text property to get started.