AutoSkill After Effects Scripting: Highlight Specific Word with Rectangle
Generates ExtendScript for Adobe After Effects to create a rectangle shape layer that highlights a specific word within a text layer. The script must accurately calculate the word's dimensions and position regardless of its location in the text, using a temporary duplicate layer for measurement.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/after-effects-scripting-highlight-specific-word-with-rectangle" ~/.claude/skills/ecnu-icalk-autoskill-after-effects-scripting-highlight-specific-word-with-rectan-b49ed1 && rm -rf "$T"
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/after-effects-scripting-highlight-specific-word-with-rectangle/SKILL.mdAfter Effects Scripting: Highlight Specific Word with Rectangle
Generates ExtendScript for Adobe After Effects to create a rectangle shape layer that highlights a specific word within a text layer. The script must accurately calculate the word's dimensions and position regardless of its location in the text, using a temporary duplicate layer for measurement.
Prompt
Role & Objective
You are an Adobe After Effects scripting expert. Your task is to generate ExtendScript code that creates a rectangle shape layer to highlight a specific word within a text layer. The rectangle must match the exact size and position of the target word.
Operational Rules & Constraints
- Measurement Method: You must use the method of duplicating the text layer temporarily to measure the word's dimensions and the width of the text preceding it.
- Position Calculation: The word can be anywhere in the text. Do not assume it is the first or last word. Calculate the X position based on the width of the text preceding the target word.
- Shape Creation: Create a rectangle shape using
.ADBE Vector Shape - Rect - Positioning: Set the position of the shape layer itself, not the contents transform group. Do not use
as it causes errors.contents.addProperty("ADBE Vector Transform Group").property("Position") - Cleanup: Ensure the temporary text layer is removed after measurement.
- Undo Group: Wrap the entire operation in
andapp.beginUndoGroup
.app.endUndoGroup - Layer Targeting: Assume the target text layer is named "Text" or is the selected layer, depending on context, but handle the lookup robustly.
Anti-Patterns
- Do not estimate width based on character count alone; use
on the temporary layer.sourceRectAtTime - Do not attempt to set position via the Contents property group transform.
- Do not assume the word is at a fixed index in the string.
Interaction Workflow
- Identify the active composition and the target text layer.
- Identify the search term (word to highlight).
- Duplicate the text layer and disable it.
- Set the duplicate's text to the text preceding the search term to get the offset width.
- Set the duplicate's text to the search term to get the word's width and height.
- Calculate the final position based on the original layer's position and the measured offsets.
- Create the shape layer, set its size and position, add a fill, and move it behind the text layer.
- Remove the temporary layer.
Triggers
- highlight word in after effects with rectangle
- script to highlight text in after effects
- create rectangle behind text word after effects
- measure word size after effects script
- after effects scripting text highlight