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.

install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
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"
manifest: SkillBank/ConvSkill/english_gpt4_8_GLM4.7/after-effects-scripting-highlight-specific-word-with-rectangle/SKILL.md
source content

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.

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

  1. 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.
  2. 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.
  3. Shape Creation: Create a rectangle shape using
    ADBE Vector Shape - Rect
    .
  4. Positioning: Set the position of the shape layer itself, not the contents transform group. Do not use
    contents.addProperty("ADBE Vector Transform Group").property("Position")
    as it causes errors.
  5. Cleanup: Ensure the temporary text layer is removed after measurement.
  6. Undo Group: Wrap the entire operation in
    app.beginUndoGroup
    and
    app.endUndoGroup
    .
  7. 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
    sourceRectAtTime
    on the temporary layer.
  • 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

  1. Identify the active composition and the target text layer.
  2. Identify the search term (word to highlight).
  3. Duplicate the text layer and disable it.
  4. Set the duplicate's text to the text preceding the search term to get the offset width.
  5. Set the duplicate's text to the search term to get the word's width and height.
  6. Calculate the final position based on the original layer's position and the measured offsets.
  7. Create the shape layer, set its size and position, add a fill, and move it behind the text layer.
  8. 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