Creating Animation Sequences in PowerPoint 2002 and PowerPoint 2003 (Part 2)

 

Andrew May
Microsoft Corporation

June 2004

Applies to:
    Microsoft Office PowerPoint 2003
    Microsoft PowerPoint 2002

Summary: Learn how to use a completely redesigned and greatly expanded section of the PowerPoint object model for creating, customizing, and controlling the animation effects on a slide. Discover how the new TimeLine object model provides more flexibility and options for richer animations then ever before. (14 printed pages)

Contents

Introduction
Inheriting Sequences from a Master Slide
Object Model Maps
Conclusion

Introduction

In Creating Animation Sequences in PowerPoint 2002 and PowerPoint 2003 (Part 1), we introduced the completely redesigned and expanded object model available in Microsoft PowerPoint 2002 and Microsoft Office PowerPoint 2003 for creating, customizing, and controlling the animation effects on a slide. We discussed how a slide's timeline structure enables you to add multiple animation sequences per slide, and multiple animation effects to the shapes on the slide. We also discussed how to add animation sequences and effects programmatically.

In this article, we discuss how to order the effects in a sequence, control the timing and triggers for the effects, and specify effect behavior.

Ordering the Effects in a Sequence

The effects in a sequence are animated in order by index, lowest to highest. By default, Effect objects are indexed in the order in which they are added to the Sequence collection. If you explicitly set the index of an effect, PowerPoint re-orders the indexes of the other Effect objects in the sequence accordingly.

In addition to setting the index of an effect when you add it to the sequence, the object model provides three methods that enable you to change an Effect object's place in the animation order of a sequence: MoveBefore, MoveAfter, and MoveTo. MoveBefore and MoveAfter let you change the Effect object's animation order relative to the position of another Effect object. That is, you specify the effect which you want to move another effect immediately in front of, or immediately behind, regardless of its index. Conversely, the MoveTo method lets you specify a specific animation order. You specify the index value you want to assign an effect. When PowerPoint executes any of these methods, it re-orders the indexes of the Effect objects in a Sequence object accordingly.

Index order is not the sole determinant of the order in which PowerPoint executes animation effects. The timing properties you set for each Effect object can have an effect as well, as we see in the next section.

Controlling Triggers and Timing in Your Sequence

Just as important as deciding what animation effects you want for a shape is specifying how you want to initiate, or trigger, those effects. Three properties in the Timing object, a child of the Effect object, let you specify how and when you want the effects in your animation sequence to run:

  • Use the TriggerType property to specify what kind of action you want to trigger the effect, such as the user clicking a shape or the page, or even having an effect triggered at the same time or after the previous effect runs.
  • If you set the trigger type for an effect to be the user clicking a shape, use the TriggerShape property to specify which shape. The trigger shape does not have to be the shape on which the animation effect is performed.
  • Use the TriggerDelayTime property to specify, in seconds, the delay from when a trigger is enabled to when the effect is performed. You can set a delay for any of the following trigger types: MsoAnimTriggerTypeAfterPrevious, MsoAnimTriggerTypeOnPageClick, MsoAnimTriggerTypeOnShapeClick, and MsoAnimTriggerTypeWithPrevious.

There are many ways to combine these three properties to get the timing and behavior you want for your animation sequence. For example, suppose you wanted the main sequence of a slide to automatically start 10 seconds after the slide is loaded. You would set TriggerType to MsoAnimTriggerTypeWithPrevious or MsoAnimTriggerTypeAfterPrevious, and TriggerDelayTime to 10, as in the code sample below.

  With .TimeLine.MainSequence.Item(1).Timing
    .TriggerType = msoAnimTriggerAfterPrevious
    .TriggerDelayTime = 10
  End With

PowerPoint considers both effect index order and timing properties when determining the order in which it performs the effects in a sequence. For effects where the trigger type is MsoAnimTriggerTypeAfterPrevious, MsoAnimTriggerTypeOnPageClick, or MsoAnimTriggerTypeOnShapeClick, then the index order is the main determinant. However, suppose multiple Effect objects have a trigger type of MsoAnimTriggerTypeWithPrevious. In this case, the index of each individual effect is less important, as PowerPoint performs all the effects at the same time.

Duplicating Effects and Assigning Specialized Behavior

The Sequence collection contains several methods that enable you to assign some specialized behaviors to your effects.

Use the Clone method to duplicate an Effect object and add it to a Sequence collection. The Effect can be from another sequence, or slide, or even another presentation altogether. As long as you pass the method a valid reference to an Effect object, a new effect with the exact same properties is added to the Sequence collection from which the method is called. Note that the cloned effect is still assigned to the same shape as the original effect.

The various ConvertTo[Behavior] methods enable you to assign certain types of specific behavior to an Effect object. For example, the ConvertToAnimateInReverse method enables you to specify that the effect animate the text in reverse order, and the ConvertToBuildLevel enables you to specify the effect build level for text, charts, and diagrams (build levels are discussed in greater detail later.) Executing one of these methods sets a corresponding read-only property in the Effect object's EffectInformation property, as shown in the following table.

Table 1. Sequence collection methods and their related properties

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

Be aware that using the ConvertToBuildLevel method may actually change the number of Effect objects in a Sequence collection. When PowerPoint executes any of these methods, it re-orders the indexes of the Effect objects in a Sequence collection accordingly.

Consider the example below, which is a variation of the earlier code that added text build effects. As before, the code adds a new slide, adds text to the text placeholder, and sets the indent level of each paragraph. The code then calls the AddEffect method, passing a build level value of msoAnimateLevelNone. One Effect object is created. Then the code calls the ConvertToBuildLevel method, and converts that effect to a build level of msoAnimateByFourthLevel, so that all four paragraphs are animated individually. Because of this, there are now four Effect objects; one for each paragraph.

Sub DemonstrateConvertEffects()
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 = "Convert Effects Demo"
                    
            '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, _
                    trigger:=msoAnimTriggerOnPageClick, _
                    Level:=msoAnimateLevelNone)
                MsgBox Prompt:="This sequence has " & .Count & " effect.", _
                    Title:= "Animate Level None"
                .ConvertToBuildLevel Effect:=efftextfly, _
                    Level:=msoAnimateTextByFourthLevel
                MsgBox Prompt:="This sequence has " & .Count & " effects.", _
                    Title:= "Animate By Fourth Level"
             End With
            End If
        Next
    End With
End With
End Sub

The EffectParameter object also contains properties that enable you to modify some other commonly-used effect characteristics. The following table lists those properties, their return types, the kind of effect they apply to, and a brief description. All the listed properties are read/write.

Table 2. Properties of the EffectParameter object

Property Return Type Effect Description
Amount Single Rotation The number of degrees a shape is rotated around its z-axis. This works on the Spin, Transparency, and Wheel effects.
Color2 ColorFormat object Color-cycle The color on which to end a color-cycle animation.
Direction MsoAnimDirection Direction The direction used for the effect.
Font Name String Font The font name of the final font of an effect.
Relative MsoTriState Motion path Whether the motion position is relative to the position of the shape.
Size Single Font The final font size of an effect. Also works on the GrowShrink effect, enabling you to specify final percentage of original size.

Specifying Effects for Media Objects

If you assign an Effect object to a media object, such as a movie or sound file, you can use the PlaySettings object to specify media actions, such as playing the media file. A media object is a Shape object whose Type property returns msoMedia. You can add a media object to a slide using the Shape.AddMediaObject method.

The following example inserts an .avi file as a media object, and then inserts an animation effect into the main animation sequence for the slide. It also specifies custom behavior for the .avi file during the animation.

Dim shpMovie As Shape
Dim effMovie As Effect

With ActivePresentation.Slides(7)
    Set shpMovie = .Shapes.AddMediaObject _
        (FileName:="C:movie.avi", _
        Left:=100, _
        Top:=100)
    With .TimeLine.MainSequence
        Set effMovie = .AddEffect(Shape:=shpMovie, _
            effectId:=msoAnimEffectAppear)
        With effMovie.EffectInformation.PlaySettings
            .LoopUntilStopped = msoTrue
            .RewindMovie = msoTrue
        End With
    End With
End With

Issues Concerning Specifying Play Settings for a Media File

There are additional custom behaviors you can set for media effects; however, setting these behaviors programmatically may have unexpected and undesirable results on other animation effects on your slide. Because of a flaw in the object model, if you access certain PlaySettings properties, PowerPoint assumes you are doing so through the AnimationSettings object, and deletes animation effects not supported in PowerPoint 2000, as described previously. Accessing the following properties trigger this undesired behavior:

  • ActionVerb
  • HideWhileNotPlaying
  • PauseAnimation
  • PlayOnEntry
  • StopAfterSlides

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 does not delete them.

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.

Creating Effects that Play, Pause, or Stop Media Objects

Alternately, you can create effects that play, pause, or stop a media object without accessing the PlaySettings object. There are three effect types that control the playing of a sound or movie file: MsoAnimEffectMediaPause, MsoAnimEffectMediaPlay, and MsoAnimEffectMediaStop. By assigning effects of these effect types to a Media object, you can control when the audio or video file plays during your animation sequence, without accessing the PlaySettings object.

The following example adds effects for a video file to a slide's main animation sequence. When the user clicks the page, the video file plays for 10 seconds, then pauses for 10 seconds, then starts playing for another 10 seconds before it stops. To accomplish this, the code adds four effects to the sequence. The first starts the file playing; the second pauses the file; the third starts the file playing again; and the final effect stops the file playing. The first effect is triggered when the user clicks the page; the other three are set to be triggered with the previous effect. The code ensures the trigger delay time for each effect is set to different durations; otherwise, PowerPoint performs all the effects simultaneously.

Note that the third effect, the one that resumes the file playing from the point where it paused, is of type MsoAnimEffectMediaPause rather than type MsoAnimEffectMediaPlay. This effect type actually has the effect of toggling whether the file is paused or not. In this sample, the first MsoAnimEffectMediaPause pauses the file, while the second cancels the pause and enables the file to resume playing. If the code inserted an MsoAnimEffectMediaPlay effect in place of the second MsoAnimEffectMediaPause effect, the video file would play from the beginning of the file, not the point at which it was paused.

Dim shpVideo As Shape
Dim effPause As Effect
Dim effPlayAgain As Effect
Dim effStop As Effect

With ActivePresentation.Slides(1)
    Set shpVideo = .Shapes("demovideo")
    
    With .TimeLine.MainSequence
        .AddEffect Shape:=shpVideo, _
            effectId:=msoAnimEffectMediaPlay, _
            trigger:=msoAnimTriggerOnPageClick
        Set effPause = .AddEffect(Shape:=shpVideo, _
            effectId:=msoAnimEffectMediaPause, _
            trigger:=msoAnimTriggerWithPrevious)
        effPause.Timing.TriggerDelayTime = 10
        Set effPlayAgain = .AddEffect(Shape:=shpVideo, _
            effectId:=msoAnimEffectMediaPause, _
                trigger:=msoAnimTriggerWithPrevious)
        effPlayAgain.Timing.TriggerDelayTime = 20
        Set effStop = .AddEffect(Shape:=shpVideo, _
            effectId:=msoAnimEffectMediaStop, _
                trigger:=msoAnimTriggerWithPrevious)
        effStop.Timing.TriggerDelayTime = 30
    End With
End With

For more information about inserting media objects and OLE objects, see Adding Multimedia to a PowerPoint 2003 Presentation.

Customizing the Animation Behavior of Your Effects

Each animation effect is 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.

Inheriting Sequences from a Master Slide

By default, a new blank slide contains no effects or interactive sequences. However, a slide may inherit main or interactive sequence effects from the master slide applied to it. A masterslide is a kind of slide template that stories information about the design template applied, such as font styles, the sizes and positions of placeholder shapes, background design, and color schemes.

A master slide also has a TimeLine object, which may include sequences, including a main sequence. So for a specified slide, there may actually be two main sequences: one contained in the TimeLine object of the specific slide, and one contained in the TimeLine object of the master slide you applied to the slide. When you are editing a presentation, these main sequences are separate. However, when you show the presentation, the two sequences are combined into a single, composite main sequence. All the effects from the master slide's main sequence play in their specified order first, and then all the effects from the individual slide's main sequence play in their specified order.

You cannot access this combined main sequence, either programmatically or through the user interface. You can, of course, access the respective main sequences of the master slide and normal slide.

Interactive sequences in a master slide are independent from any interactive sequences contained in the slide to which you apply the master. They are triggered by the specified user action, just as normal interactive sequences.

Also, the number of effects a normal slide inherits from a master slide may not match the number of effects present in the main sequence of the master slide. This happens when the master slide's main sequence contains build effect for a placeholder text box, chart, or diagram. In these cases, the main sequence contained in the master slide only indicates the build settings to apply to the shape in the slide to which the master slide is applied, not the actual number of effects that exist. For example, suppose on a specified master slide, the body text placeholder specifies that text effects build to the fifth level. The placeholder on the master slide shows one paragraph at each bullet point level, or five paragraphs total. There are five effects, one for each paragraph, for this build in the master slide's main sequence. However, you only have two bullet points in the actual text on the individual slide. When you show the presentation, there are only two effects for this build in the combined main sequence.

Object Model Maps

The following diagrams detail the structure of the TimeLine object model section, from the TimeLine object down to the children of the Effect object. The AnimationBehaviors collection, which provides granular control over the specific behaviors that comprise an effect, is beyond the scope of this article and as such is not diagrammed.

Figure 1. TimeLine object and its children

Figure 2. Effect object and its children

Figure 3. Effect Information object and its children

Figure 4. Timing and EffectParameters objects

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 want to go further and define or control every aspect of an animation effect's behavior.