How to Implement PowerPoint Animations and Transitions with OfficeCLI

OfficeCLI implements PowerPoint animations and transitions by emitting OOXML <p:timing> and <p:transition> blocks through a dual-layer architecture that separates semantic modeling from raw XML passthrough.

OfficeCLI treats PowerPoint animations and slide transitions as first-class elements, allowing developers to programmatically control presentation behavior via command-line operations. The tool maps high-level animation properties to Open XML specifications while preserving advanced constructs through raw passthrough. This implementation enables both full editability of common features and lossless round-tripping of complex PowerPoint effects.

Understanding the Animation Architecture

The OOXML Timing Model

Animations in OfficeCLI are fundamentally tied to the OOXML <p:timing> specification. Each animation lives under a target shape or chart and is represented internally as an add animation batch row. The system builds a per-shape animation index that tracks timing relationships and effect sequences.

In src/officecli/Handlers/Pptx/PptxBatchEmitter.cs, the emitter constructs these animation trees by iterating through shape indices and generating corresponding <p:timing> nodes. This file handles the core translation from OfficeCLI's semantic model to actual PowerPoint markup, including complex scenarios like exotic transitions that the standard SDK cannot fully model.

Batch Emission and Indexing

The PptxBatchEmitter class manages the dual-layer emission strategy. For animations, it processes batch operations that specify target shapes, effect types, and timing parameters. The emitter validates that animation properties conform to the Open XML schema before writing the final XML nodes.

This architecture ensures that animations maintain their structural integrity across save operations, with the emitter preserving the ordered list of animations per slide as defined in the source code.

Setting Shape Animations

The SetShapeAnimationByPath Method

The primary entry point for assigning animations is SetShapeAnimationByPath, implemented in src/officecli/Handlers/Pptx/PowerPointHandler.Set.Shape.cs. This method extracts the target shape or chart by path, then enumerates existing animation "child time nodes" using EnumerateShapeAnimationCTns to determine whether to replace an existing animation or append a new one.

The method enforces read-only facets including presetId, easein, easeout, and motionPath to maintain OOXML consistency. When processing properties, it validates animation classes (entrance, exit, emphasis, motion) and maps them to the appropriate OOXML preset identifiers.

Animation Properties and Validation

OfficeCLI supports two property input styles. Users can employ the compound animation= shortcut for quick assignments, or use the expressive element form with individual property flags for granular control.

Valid animation properties include:

  • effect – The specific animation preset (e.g., fade, fly, zoom)
  • class – Animation category (entrance, exit, emphasis, motion)
  • trigger – Activation method (onClick, afterPrevious, withPrevious)
  • duration and delay – Timing in milliseconds
  • repeat and autoReverse – Looping behaviors

The handler in PowerPointHandler.Set.Shape.cs parses these properties at lines 55-78, assembling them into a DocumentNode that the batch emitter later converts to OOXML.

Motion Path Animations

When class=motion is specified, OfficeCLI handles vector-based movement paths. The path property accepts either preset motion paths or custom SVG-like coordinates via the d= parameter. Custom paths are interpreted as coordinates normalized to the slide dimensions and stored as motionPath in the resulting OOXML.

Implementing Slide Transitions

Transition Emission Strategy

Slide transitions operate separately from shape animations in OfficeCLI. The PptxBatchEmitter processes transitions by stripping user-provided transition properties from the standard semantic emit path, then appending a raw <p:transition> slice immediately after the slide element. This approach accommodates both standard transitions and "exotic" variants such as morph effects that require specialized XML handling.

As implemented in src/officecli/Handlers/Pptx/PptxBatchEmitter.cs (lines 540-108), this strategy ensures that transition definitions survive round-trip operations even when the underlying Open XML SDK lacks full support for the specific transition type.

The Transition Helper

The PowerPointHandler.Helpers.Transition.cs file contains utility methods for creating or locating existing <p:transition> elements. This helper safely handles unknown or alternate-content transitions by checking for existing transition nodes before insertion, preventing duplicate definitions while maintaining XML schema validity.

Slide-level transition properties are parsed in src/officecli/Handlers/Pptx/PowerPointHandler.Set.Slide.cs, which handles transition, transitionSpeed, and transitionDuration parameters.

Property Syntax and Timing Chains

Shortcut vs. Element Form

OfficeCLI accepts animation parameters through two distinct syntax patterns. The shortcut form uses a compound string:

officecli add deck.pptx /slide[2]/shape[3] --prop animation=fade-entrance-800

The element form provides explicit control over individual facets:

officecli add deck.pptx /slide[2]/shape[3] --type animation \
  --prop effect=fade --prop class=entrance --prop duration=800 \
  --prop trigger=onClick --prop delay=200

Both forms return individual properties on get operations, making the model fully round-trippable except for specific template-exit effects as documented in examples/ppt/animations.md.

Chaining Animation Triggers

Animations execute based on trigger relationships that define sequencing behavior. The trigger property accepts three primary values that enable self-playing sequences:

  • onClick – Requires user interaction to start
  • afterPrevious – Executes when the preceding animation completes
  • withPrevious – Executes simultaneously with the preceding animation

To build a self-playing sequence, chain multiple add commands with complementary triggers:

officecli add deck.pptx /slide[6]/shape[2] --type animation \
  --prop effect=fade --prop class=entrance --prop trigger=onClick --prop duration=500

officecli add deck.pptx /slide[6]/shape[3] --type animation \
  --prop effect=fly --prop class=entrance --prop trigger=afterPrevious --prop duration=600

officecli add deck.pptx /slide[6]/shape[4] --type animation \
  --prop effect=zoom --prop class=entrance --prop trigger=withPrevious --prop duration=600

Working Code Examples

Add a simple entrance animation to shape 3 on slide 2:

officecli add deck.pptx /slide[2]/shape[3] --type animation \
  --prop effect=fade --prop class=entrance --prop duration=800

Add a motion-path animation with a custom SVG path:

officecli add deck.pptx /slide[5]/shape[8] --type animation \
  --prop class=motion --prop path=custom \
  --prop d='M 0 0 L 0.3 -0.1 L 0.6 0.1 E' --prop duration=1500

Set a slide transition with speed control:

officecli set deck.pptx /slide[1] --prop transition=fade \
  --prop transitionSpeed=slow

Summary

  • OfficeCLI implements PowerPoint animations by emitting OOXML <p:timing> blocks through PptxBatchEmitter.cs, while transitions use separate <p:transition> elements handled by the transition helper.
  • The SetShapeAnimationByPath method in PowerPointHandler.Set.Shape.cs manages animation assignment, validation, and read-only facet enforcement for properties like presetId and motionPath.
  • Animation triggers (onClick, afterPrevious, withPrevious) enable complex sequencing behaviors by defining temporal relationships between consecutive effects.
  • The tool supports both compound shortcut syntax and explicit element properties, with custom motion paths accepting SVG-like coordinate strings normalized to slide dimensions.
  • A dual-layer architecture separates semantic emission from raw XML passthrough, ensuring compatibility with both standard animations and exotic transition types like morph.

Frequently Asked Questions

How does OfficeCLI handle custom motion paths in PowerPoint animations?

OfficeCLI stores custom motion paths as motionPath properties in the OOXML when class=motion is specified. The d parameter accepts SVG-like path data (e.g., M 0 0 L 0.3 -0.1 L 0.6 0.1 E) which is normalized to slide coordinates during emission. This implementation resides in the shape animation handler at src/officecli/Handlers/Pptx/PowerPointHandler.Set.Shape.cs, ensuring custom vector animations render correctly across different slide dimensions.

What is the difference between animation triggers in OfficeCLI?

OfficeCLI supports three trigger types that control execution timing: onClick requires manual advancement, afterPrevious creates sequential chains by starting when the prior animation finishes, and withPrevious enables parallel execution with the preceding effect. These triggers are processed in the timing chain within PptxBatchEmitter.cs, allowing developers to build everything from manual presentations to fully automated slide sequences without additional scripting.

Can OfficeCLI preserve complex PowerPoint transitions that standard tools cannot edit?

Yes, OfficeCLI employs a raw passthrough mechanism for exotic transitions such as morph effects. The emitter in PptxBatchEmitter.cs strips transition properties from the semantic path and appends raw <p:transition> XML slices after the slide element. This approach, combined with the transition helper in PowerPointHandler.Helpers.Transition.cs, ensures that advanced transitions survive round-trip operations even when the underlying Open XML SDK lacks native support for the specific transition variant.

How are animation properties validated before being written to the PPTX file?

Validation occurs in PowerPointHandler.Set.Shape.cs where the SetShapeAnimationByPath method enforces read-only facets and checks animation class compatibility. The method prevents modification of restricted properties like presetId, easein, and easeout while ensuring that effect names and trigger values conform to the OOXML specification. Invalid combinations are caught during the batch emission phase before any XML is written to the presentation file.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →