Comparing Ways to Control Animation in PowerPoint 2002 and PowerPoint 2003

 

Andrew May
Microsoft Corporation

June 2004

Applies to:
    Microsoft® Office PowerPoint® 2003
    Microsoft Office PowerPoint 2002

Summary: Learn why using the TimeLine section of the Microsoft Office PowerPoint 2003 object model is the recommended way to work programmatically with animation effects for your slides. We discuss how the TimeLine object model section differs from the AnimationSettings object model section, and the advantages that using the TimeLine object model for creating, customizing, and controlling animation effects offers. (13 printed pages)

Contents

Introduction
Advantages of the Using the TimeLine Object Model_
Compatibility Issues
How the AnimationSettings Object Model is Structured
How the TimeLine Object Model is Structured
Moving from Using AnimationSettings to Using TimeLine
Writing Code Using the AnimationSettings and TimeLine Object Models
Conclusion

Introduction

In Microsoft® Office PowerPoint® 2003, the term animation refers to special visual or sound effects you add to text or an object. Animation effects give motion to text, pictures, and other content on your slides. Besides adding action, they help you steer audience focus, emphasize important points, transition between slides, and maximize slide space by moving things on and off the slide.

PowerPoint 2002 added a completely redesigned and greatly expanded object model for creating, customizing, and controlling the animation effects on a slide. This new object model, contained in the TimeLine object, provides more flexibility and options for richer interactive animations then ever before. At the same time, in order to provide backward compatibility, PowerPoint retained the previous object model structure dealing with animation effects, contained in the AnimationSettings object.

In this article, we compare the structure of the two object models, and offer users familiar with the AnimationSettings object model information on using the TimeLine object model. But first, let's briefly touch on the advantages using the TimeLine object model offers in terms of more robust, nuanced animation behaviors and interactive animation sequences.

Advantages of the Using the TimeLine Object Model

If you are programming for PowerPoint versions 2002 and later, you should be using the TimeLine object model for dealing with animation effects; the AnimationSettings object model should only be used for PowerPoint versions 2000 and below. If you haven't used the AnimationSettings object model before, and just want information on how to create slide animations in the newer versions of PowerPoint, see Creating Animation Sequences in PowerPoint 2002 and 2003, which discusses the TimeLine object model in greater detail.

The advantages of using the TimeLine object model include:

  • The ability to define multiple independent animation sequences that are initiated by user interaction with the slide, in addition to the main animation sequence the AnimationSettings object model provided.
  • The ability to specify multiple animation effects for the same shape, including entry, emphasis, and exit effects. You can do this within the same animation sequence, as well as specify animation effects for the same shape in different sequences.
  • The ability to control the exact behavior, timing, and scope of your effects to a greater degree than ever before, and so to create more nuanced, customized effects.

Compatibility Issues

Unfortunately, because of basic differences in their organization, the two object models are not compatible. Using the AnimationSettings object model for programming PowerPoint 2002 and above is not recommended, as it can have unexpected and undesirable results for your animation sequences. Unlike the PowerPoint 2002 and PowerPoint 2003 object models, the only animation effects the PowerPoint 2000 and earlier object models support are entry effects. When you use the AnimationSettings object to set effect properties, PowerPoint assumes you are programming for the PowerPoint 2000 or earlier object models, and therefore takes the following actions:

  • Deletes any animation effects that are not entry effects, for the entire slide. This includes effects that you added using the user interface.
  • Converts any entry effects that are only available in PowerPoint version 2002 or later to effects of type ppEffectAppear.
  • Removes all custom timing for entry effects, as PowerPoint 2000 and below do not allow for custom timing of animations.
  • Deletes interactive sequences for the slide, as interactive sequences are not supported in PowerPoint 2000 and earlier versions.

How the AnimationSettings Object Model is Structured

To understand how the new TimeLine object model provides this increased functionality, let's first examine how the AnimationSettings object model is organized.

The AnimationSettings object model is fairly straight forward. Each shape on a specified slide contains an AnimationSettings object, which contains properties dealing with the shape's animation effect, including its place in the order of animation effects for that slide. In this model, a shape's animation effect is also referred to as its entry effect, since the animation is only performed as the shape enters the slide. Only shapes for which you specify an animation effect have an AnimationSettings object; objects with no animation effect appear on the slide when it is loaded. Having the AnimationSettings object as a child of the Shape object makes sense, as each shape has a single animation effect in this model. Figure 1 illustrates this structure.

Figure 1. Conceptual structure of the AnimationSettings object model

Note that in this structure, there is a single, implied sequence of animation effects. Once the slide is loaded, that sequence starts and moves through its effects until the sequence is completed or the user changes slides.

Unfortunately, while the AnimationSettings object model is uncomplicated, it is also correspondingly linear, and limited. There is only one progression of animation effects per slide, and you can only assign one animation effect per shape.

How the TimeLine Object Model is Structured

The TimeLine object model greatly expands on, and supersedes, the structure of the AnimationSettings object model. This new object model section not only lets you create multiple animation sequences per slide, and assign multiple animation effects to a specified shape. It also provides a level of control that allows you to create, customize and combine animation behaviors into your own custom effects.

The first two major conceptual changes we need to discuss are:

  • The concept of an animation sequence is made explicit. Not only that, but you can create multiple animation sequences per slide.
  • Each animation effect is no longer a child of a Shape object, but a separate object that includes a reference to the shape it animates. Because of this, you can assign multiple effects, in multiple sequences, to animate the same shape.

These changes are reflected in the structure of the TimeLine object model at the highest level, in the fact that the TimeLine object model is contained in the Slide object, rather than the Shape object.

The TimeLine object itself is a container for the animation sequences you create for a slide. The implied single animation sequence of the AnimationSettings object model is made explicit as the main sequence in the TimeLine object. The main sequence is the animation sequence that starts by default when the slide loads. In addition, however, you can create any number of other sequences that can be triggered by user interaction at any time while the slide displays. These interactive sequences may run concurrently with the main sequence, or after, or not at all, based on the user's actions.

For each interactive sequence, you designate one shape as the trigger shape; when the user clicks on that shape during the presentation, the interactive sequence starts.

Each sequence in turn is a collection of ordered animation effects, each of which is assigned to animate a specific shape. Because the animation effects are now organized separate from the shape they affect, you can assign any number of effects to a single shape. You can specify one effect for when the shape enters the slide, one or more if you want the shape to be animated as the sequence progresses, and a totally different effect if you want the shape to exit the slide. In addition, multiple sequences can contain effects that animate the same shape.

The figure below illustrates the timeline of an example slide, which contains one main sequence and two interactive sequences.

Figure 2. Conceptual structure of the TimeLine object model

This example shows some of the flexibility and complexity available to you by using the TimeLine object model. In this example, the slide has a main sequence that starts as soon as the slide loads. Notice that the main sequence contains two effects for both Shape B and E. The effects assigned to Shape B run one after the other, while the first effect assigned to Shape E runs, then an effect for Shape F runs, and then the second effect for Shape E is performed. Also, Shapes B, D, E, and F are each animated as part of the main sequence and one of the interactive sequences. Lastly, the interactive sequences animate slide shape in a different order than the main sequence.

The other major revision of the animation conceptual model is that each animation effect is now made up of one or more sub-units, called animation behaviors. The various types of animation behaviors let you control and customize discreet aspects of each animation effect to a greater extent than ever before. Each Effect object includes an AnimationBehaviors collection, which contains the individual AnimationBehavior objects that collectively describe the animation effect performed on the specified shape. Each AnimationBehavior object is of a specific type; each type specifies a discreet aspect of the effect behavior, such as:

  • Rotation effect
  • Scale effect
  • Set effect
  • Color effect
  • Command effect
  • Filter effect
  • Motion effect
  • Property effect

The AnimationBehavior object is best thought of as a base class that contains the common properties shared by all animation behaviors. In addition, each AnimationBehavior object also includes one child object, based on its type, that contains the properties specific to that type of animation behavior. For example, an AnimationBehavior object that represents a rotation behavior contains a RotationEffect object.

Use the Type property of the AnimationBehavior object to return an animation behavior's type.

Detailing the properties of each animation behavior and how to customize and combine them to create exactly the animation effect you want is beyond the scope of this article. For more information, see the Microsoft Office PowerPoint 2003 Visual Basic Language Reference.

Moving from Using AnimationSettings to Using TimeLine

All of this new complexity might seem a little overwhelming if you're used to using the AnimationSettings object model, and all you want to do is specify standard effects for shapes. But most of the properties you used to control animation effects using the AnimationSettings object model have direct counterparts in the TimeLine object model.

The table below lists the properties of the AnimationSettings object, and the corresponding property or method under the TimeLine object model. Note that in many cases, the properties have slightly different attributes (such as read-only instead of read/write access), or return slightly different information. These differences are addressed below.

Table 1. Corresponding properties between object model sections

AnimationSettings property TimeLine object TimeLine property
AnimationSettings property Object Property
AdvanceMode Timing TriggerType
AdvanceTime Timing TriggerDelayTime
AfterEffect EffectInformation AfterEffect
Animate Not used  
AnimateBackground EffectInformation AnimateBackground
AnimateTextInReverse EffectInformation AnimateTextInReverse
AnimationOrder Effect Index
Application EffectInformation Application
ChartUnitEffect EffectInformation BuildByLevelEffect
DimColor EffectInformation Dim
EntryEffect Effect EffectType
Parent Effect Shape
PlaySettings EffectInformation PlaySettings
SoundEffect EffectInformation SoundEffect
TextLevelEffect EffectInformation BuildByLevelEffect
TextUnitEffect EffectInformation TextUnitEffect

Advancing to the next animation effect

There are no properties that directly correspond to AdvanceMode and AdvanceTime, although the three "trigger" properties of the Timing object expand and refine the ways you can advance an animation sequence. The TriggerType property is the closest analog to the AdvanceMode property. It offers four ways to advance to the next effect, as opposed to the two offered by the AdvanceMode property. The options are: after the previous effect, when the page is clicked, when a specific shape is clicked, or with the previous effect.

You can use the TriggerDelayTime property to delay an effect from running, just as you can with the AdvanceTime property. However, where you can only set an advance time if the AdvanceMode property is specified as "on time," you can set a trigger delay time for any of the TriggerType constants. For example, if you wanted a shape to enter the slide 10 seconds after the page is clicked, simply set the TriggerType property to MsoAnimTriggerTypeOnPageClick and the TriggerDelayTime to 10.

There is no "on time" constant for the TriggerType property. To have an effect automatically run a certain amount of time after the previous effect, including upon slide load, set the TriggerType property to AfterPrevious, and the TriggerDelayTime property****to the desired number of seconds.

You can also set the TriggerType property to WithPrevious, and use the TriggerDelayTime property to specify when to perform the effect, relative to the previous effect.

As mentioned earlier, for each interactive sequence, you designate a trigger shape; the interactive sequence starts when the user clicks that shape. To specify a trigger shape for a sequence, set the Timing.TriggerShape property of the first Effect object in the timeline of the sequence to the desired shape.

Selecting which shapes get animated

The Animate property has no counterpart in the TimeLine object model. If an effect is assigned to a shape (that is, if the Effect.Shape property is set to that shape), then the shape is animated. You can also use the Sequence.FindFirstAnimationFor method to determine if a shape has any effect applied to it for a particular sequence. If no effect is assigned to a shape, the shape is not animated. Also, because the TimeLine object model supports effects other than entry effects, a shape may not have an entry effect, but other effects such as emphasis or exit.

In the AnimationSettings object model, you determine the order in which the animation effects took place by setting the AnimationOrder property. Under the TimeLine object model, the animation order is reflected in the read-only Effect.Index property. By default, effects are indexed and performed in the order in which you add them to the Sequence collection. You can set the index explicitly when adding an effect using an optional parameter of the Sequence.AddEffect method, or later by using one of the methods that change an effect's place in the sequence: MoveAfter, MoveBefore, or MoveTo.

Setting read-only effect information

Some of the properties in the EffectInformation object are read-only, while their counterparts in the AnimationSettings object are read/write. These properties are read-only in the TimeLine object model because they are set using methods that belong to the Sequence collection. Note that these methods belong to the Sequence collection, rather than the Effect object, because using them may actually increase or decrease the number of Effect objects in the collection.

Table 2. EffectInformation object properties and the corresponding Sequence collection method you use to set each property

EffectInformation object property Sequence collection method
AfterEffect ConvertToAfterEffect
AnimateBackground ConvertToAnimateBackground
AnimateTextInReverse ConvertToAnimateInReverse
BuildByEffectLevel ConvertToBuildLevel
TextUnitEffect ConvertToTextUnitEffect

Setting the type of effect

The Effect.EffectType property supersedes the AnimationSettings.EntryEffect property. However, since the TimeLine object model support more than just entry effects, the EffectType property applies to any type of effect: entry, emphasis, motion path, object action, or exit. As such, this property returns an MsoAnimEffect constant, rather than a PpEntryEffect constant.

Setting build effects

The ChartUnitEffect and TextLevelEffect properties of the AnimationSettings object are combined into the EffectInformation object's BuildByEffectLevel property. This read-only property returns the build level for charts, diagrams, and text boxes. You cannot apply build effects to diagrams using the AnimationSettings object model.

Setting media playback options

You use the same object, PlaySettings, to specify media object playback options in both object models. However, care should be taken when you access the PlaySettings object through the TimeLine object model, for the reason explained below.

**Important   **There is currently a flaw in the PowerPoint object model such that, when you access certain PlaySettings object properties, even if you do so through the TimeLine object model, PowerPoint assumes you are programming for PowerPoint 2000 or below, and deletes any animation effects that are not entry effects, for the entire slide. PowerPoint does this only at the time at which you access the PlaySettings properties. So, if you are going to set PlaySettings properties for media effects, you should do so before you add any other effects to a slide. Once you finish accessing the PlaySettings object for any media effects, you can add other effects and PowerPoint won't delete them.

Accessing the ActionVerb, HideWhileNotPlaying, PauseAnimation, PlayOnEntry, and StopAfterSlides properties trigger this undesired behavior.

Note   Because this is a flaw in the object model, you can specify these settings through the PowerPoint user interface without adverse effects on other animation effects.

Writing Code Using the AnimationSettings and TimeLine Object Models

Now that we discussed the conceptual differences of the two object models, let's examine two code samples that deal with animation effects. The first is written using the AnimationSettings object model; the second, using the TimeLine object model. Both samples do the same thing: create a slide, add title and body text, and then animate that text. The title appears using the "blind" animation effect, while the body text is animated to the third level, and flies in from the right, word by word. Both examples create the slide, and add text to the placeholder shapes on it, using the same code.

In the first sample, once you add the text and specify indent level, the code access the properties of each Shape object's AnimationSettings object in order to create animation effects. The type of effect, how it is triggered, and the animation order is all set from within the AnimationSettings object.

Dim intSlideNumber As Integer
Dim objShape As Shape

With ActivePresentation.Slides
    intSlideNumber = .Count + 1
    .Add Index:=intSlideNumber, Layout:=ppLayoutText
    With .Item(intSlideNumber)
        For Each objShape In .Shapes
            If objShape.PlaceholderFormat.Type = ppPlaceholderTitle Then
                objShape.TextFrame.TextRange.Text = "This is my title"
                 With objShape.AnimationSettings
                    .Animate = msoTrue
                    .AdvanceMode = ppAdvanceOnClick
                    .AnimationOrder = 1
                    .EntryEffect = ppEffectBlindsHorizontal
                End With
            ElseIf objShape.PlaceholderFormat.Type = _
                ppPlaceholderBody Then
            
                With objShape.TextFrame.TextRange
                    .Text = "This is the first level heading" & _
                        vbCrLf
                    .InsertAfter "This is the second level heading" & _
                        vbCrLf
                    .InsertAfter "This is the third level heading" & _
                        vbCrLf
                    .InsertAfter "This is another first level heading"
                    .Paragraphs(1, 1).IndentLevel = 1
                    .Paragraphs(2, 1).IndentLevel = 2
                    .Paragraphs(3, 1).IndentLevel = 3
                    .Paragraphs(4, 1).IndentLevel = 1
                End With
                With objShape.AnimationSettings
                    .Animate = msoTrue
                    .AdvanceMode = ppAdvanceOnClick
                    .TextLevelEffect = ppAnimateByThirdLevel
                    .AnimationOrder = 2
                    .EntryEffect = ppEffectFlyFromRight
                    .TextUnitEffect = ppAnimateByWord
                End With
            End If
        Next
    End With
End With

The second sample starts much like the first, in that the code adding the slide, identifying the title and body text placeholders and adding text to them is identical. To add the animation effects, however, the code accesses the slide's main sequence rather than the individual shapes, and adds Effect objects to it. One thing to note is that the AddEffect method call that adds effects to the body text actually adds one effect for each paragraph. You must convert each of these Effect objects to a text unit effect in order for the body text for each paragraph to fly in one word at a time.

Dim intSlideNumber As Integer
Dim objShape As Shape
Dim effTextFly As Effect
Dim intCount As Integer

With ActivePresentation.Slides
    intSlideNumber = .Count + 1
    'Add new slide with a title and text placeholder
    .Add Index:=intSlideNumber, Layout:=ppLayoutText
    With .Item(intSlideNumber)
        For Each objShape In .Shapes
            'Identify the title place holder
            If objShape.PlaceholderFormat.Type = ppPlaceholderTitle Then
                objShape.TextFrame.TextRange.Text = "This is my title"
                 .TimeLine.MainSequence.AddEffect _
                    Shape:=objShape, _
                    effectId:=msoAnimEffectBlinds, _
                    trigger:=msoAnimTriggerOnPageClick
                    
            'Indentify the text placeholder
            ElseIf objShape.PlaceholderFormat.Type = _
                ppPlaceholderBody Then
                With objShape.TextFrame.TextRange
                    'Insert four paragraphs of text
                    .Text = "This is the first level heading" & _
                        vbCrLf
                    .InsertAfter "This is the second level heading" & _
                        vbCrLf
                    .InsertAfter "This is the third level heading" & _
                        vbCrLf
                    .InsertAfter "This is another first level heading"
                    'Set indent level of each paragraph
                    .Paragraphs(1, 1).IndentLevel = 1
                    .Paragraphs(2, 1).IndentLevel = 2
                    .Paragraphs(3, 1).IndentLevel = 3
                    .Paragraphs(4, 1).IndentLevel = 1
                End With
             With .TimeLine.MainSequence
                'Add an effect for each paragraph
                'animate text down to third-level paragraphs
                'Set variable equal to first effect returned by method
                Set effTextFly = .AddEffect _
                    (Shape:=objShape, _
                    effectId:=msoAnimEffectFly, _
                    Level:=msoAnimateTextByThirdLevel, _
                    trigger:=msoAnimTriggerOnPageClick)
                'Convert each Effect just added to a unit text effect
                'so they animate the text word by word
                For intCount = effTextFly.Index To .Count
                    .ConvertToTextUnitEffect Effect:=.Item(intCount), _
                        unitEffect:=msoAnimTextUnitEffectByWord
                Next
             End With
                                
            End If
        Next
    End With
End With

The second code sample may appear more effort for the same end result. But this comparison is somewhat misleading, in that both samples were written to accomplish the same thing. Remember, the advantage of the TimeLine object model is the greatly increased flexibility and control it offers. The first sample shows a large extent of what you can do with the AnimationSettings object, while the second just scratches the surface of what you can accomplish using the TimeLine object model. We could extend the second example by adding additional effects for the shapes, or even additional interactive sequences, for example:

  • Add emphasis effects to the paragraph in the body text, such as having the text increase in size or change color.
  • Specify different effect settings for each paragraph, including completely different effects, such as a "Fly In" effect for the first paragraph, and a "Spiral In" effect for the second.
  • Add exit effects, such as moving each paragraph off the slide before the next paragraph is displayed, or moving all the paragraphs off the slide at once the text build was complete.
  • Add interactive sequences, such as sequences that move other shapes on or off the slide as another shape is clicked.
  • Set properties to adjust our effects, such as the speed at which the body text flies in word by word.

None of this is possible using the AnimationSettings object model.

Conclusion

While it may seem complicated at first glance, the TimeLine object model is relatively easy to use for adding, moving, and customizing standard animation effects for your slide. In addition, it offers a powerful level of granularity for users who really want to go deeper and define or control every aspect of an animation effect's behavior.

Note   For more about using the TimeLine object model, see Creating Animation Sequences in PowerPoint 2002 and PowerPoint 2003 (Part 1), and Creating Animation Sequences in PowerPoint 2002 and PowerPoint 2003 (Part 2).