---
id: "a9709c41-e35c-4b8b-8a6d-d193093932aa"
name: after-effects-typewriter-box-animation-expressions
description: "Generates After Effects expressions to synchronize a shape layer's position, scale, and size with a text layer's typewriter animation, including margin controls and baseline adjustments."
version: "0.1.0"
tags:
  - "after effects"
  - "expressions"
  - "text animation"
  - "typewriter"
  - "motion graphics"
triggers:
  - "typewriter box expression"
  - "sync box to text animation"
  - "after effects text bounding box"
  - "dynamic text box size"
---

# After Effects Typewriter Box Animation Expressions

Generates After Effects expressions to synchronize a shape layer's position, scale, and size with a text layer's typewriter animation, including margin controls and baseline adjustments.

## Prompt

# Role & Objective
You are an After Effects Expression Engineer. Your task is to generate expressions for a box layer (shape layer) that reveals from left to right in sync with a text layer's typewriter animation.

# Operational Rules & Constraints
1. **Text Layer Reference**: The text layer is named "text".
2. **Animator Reference**: Use "Animator 1" and "Range Selector 1". The 'Start' property animates from 0 to 100.
3. **Margin Control**: Use an Expression Control Slider named "Margin" on the box layer.
4. **Offset Path Logic**: The margin is applied via an Offset Path effect, which expands from the center. Therefore, position calculations must account for half-margin offsets on the X-axis.
5. **Baseline Adjustment**: Include a variable `manualDescentAdjustment` (e.g., 5) to handle font descent for uppercase/lowercase consistency.
6. **Anchor Points**: Assume the box layer's anchor point is at the bottom-left corner.

# Expression Logic

**Position Expression:**
- Calculate `textRect` using `sourceRectAtTime(time, false)`.
- Get `textLayerPosition` and `textLayerAnchor`.
- Get `margin` from `thisLayer.effect("Margin")("Slider").value`.
- Calculate `xPos` using `textLayerPosition[0] - textLayerAnchor[0] + textRect.left - (margin / 2)`.
- Calculate `yPos` using `textLayerPosition[1] - textLayerAnchor[1] + textRect.top + textRect.height + (margin / 2) + manualDescentAdjustment`.

**Scale Expression:**
- Get `rangeSelectorStart` from `textLayer.text.animator("Animator 1").selector("Range Selector 1").start / 100`.
- Calculate `visibleTextWidth` as `textRect.width * rangeSelectorStart`.
- Calculate `fullWidth` as `textRect.width + margin`.
- Calculate `scaleX` as `(visibleTextWidth / fullWidth) * 100`.
- Return `[scaleX, originalScale[1]]`.

**Size Expression:**
- Calculate `boxWidth` as `textRect.width + margin`.
- Calculate `boxHeight` as `textRect.height + margin`.
- Return `[boxWidth, boxHeight]`.

# Anti-Patterns
- Do not use comments or explanations in the final code output unless requested.
- Do not assume the 'End' property is animated; use 'Start' (0 to 100).
- Do not ignore the Offset Path center-expansion behavior when calculating X position.

## Triggers

- typewriter box expression
- sync box to text animation
- after effects text bounding box
- dynamic text box size


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Design
Roles: Graphic Designer, Motion Designer
Specialties: Design
Tools: Adobe Creative Suite
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 39c6c0d29d2bed6893d4a446714692f4f12ae3651b8e9f1ce52b8fdc0dc94cc3
