• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2237
  • Last Modified:

Programmatically set PowerPoint Motion Path animation

Is it possible to programmatically set a PowerPoint motion path?  I have a series of data (X,Y) that I would like to program in to an object's motion path so when someone views the slide, they will see the ball move around.  The data is being pulled from a database and placed in another slide in my presentation (although, that is not necessary - I can collect the data in vb and just set the motion path from there).  I tried recording a macro while creating a motion path on an object, but it appears as if the attributes for the motion path were not "written" during the recording process which makes me think this may not be possible.

Anyway, I'm looking for a quick and dirty way to have time-lapsed data presentation that is smooth.
0
Steve Krile
Asked:
Steve Krile
  • 7
  • 5
1 Solution
 
GlennaShawCommented:
Here's a very long discussion on programming motion paths:
http://www.eggheadcafe.com/software/aspnet/28482014/-how-to-parse-a-string.aspx
Shyam also has some motion path add-ins that might work better for you:
http://skp.mvps.org/
0
 
Steve KrileAuthor Commented:
Woof...this is an interesting conversation, but I'm having trouble stripping out the relavent bits.  Seems like this is the important part:

Sub check_for_button(strMyFile As String)

    Dim oPresentation As Presentation
    Set oPresentation = Presentations.Open(strMyFile)
    Dim oSl As Slide
    Dim y As Long
    Dim i As Long
    Dim oSh As Shape
    Dim oEffect As Effect
    Dim oShB As Shape
    Dim pathdata(20)
    Dim aniMotion As AnimationBehavior
   
    With oPresentation
   
        For Each oSl In ActivePresentation.Slides
   
            ActiveWindow.View.GotoSlide (oSl.SlideIndex)
   
                With oSl.TimeLine
   
                    For i = .MainSequence.Count To 1 Step -1
   
                        If .MainSequence(i).Shape.Type = msoTextBox Then
                            Set shpAnswer = oSl.Shapes.AddShape(msoShapeRectangle, _
                            600, 50, 100, 50)
                            shpAnswer.TextFrame.TextRange.Text = "Answer"
                            GoTo Nextsub
                        End If
                    Next
   
                End With
   
Nextsub:        With oSl.TimeLine
                    y = 1
                    For i = .MainSequence.Count To 1 Step -1
                        If .MainSequence(i).Shape.Type = msoTextBox Then
                            Set oSh = .MainSequence(i).Shape
                            pathdata(y) = .MainSequence(i).Behaviors(1).MotionEffect.Path
                            Set oEffect = oSl.TimeLine.InteractiveSequences.Add.AddEffect(Shape:=oSh, effectId:=msoAnimEffectCustom, Trigger:=msoAnimTriggerOnShapeClick)
                           
                            With oEffect.Timing
                                .Duration = 2
                                .TriggerDelayTime = 0
                            End With
                           
                            Set aniMotion = oEffect.Behaviors.Add(msoAnimTypeMotion)
                           
                            With aniMotion.MotionEffect
                                .FromX = Split(pathdata(y))(1)
                                .FromY = Split(pathdata(y))(2)
                                .ToX = Split(pathdata(y))(4)
                                .ToY = Split(pathdata(y))(5)
                            End With
   
                            oEffect.Timing.TriggerShape = shpAnswer
   
                        End If
                    y = y + 1
                    Next i
                End With
            Next oSl
   
            oPresentation.Save
            oPresentation.Close
   
        End With
   
    Set oSh = Nothing
    Set oPresentation = Nothing
End Sub


But, i can't seem to get my head around this.  Could you help me with a simple example.  Say you have one slide and on that slide is one object.  How would you write a macro to move that object on a click for instance.  Forget about collecting the data.  Let's just hard code the coordinates for now.
0
 
GlennaShawCommented:
If I jump on this boat, I'll be thinking in VB for days... (weird quirk I have, if I really start in programming I start thinking in the language and am barely fit to be around).

So instead, how about a 2 part tutorial that tells you all about how to program PowerPoint animation? :-)
http://msdn2.microsoft.com/en-us/library/aa168134(office.11).aspx
http://msdn2.microsoft.com/en-us/library/aa168135(office.11).aspx
And the specific VB reference for motion effects:
http://msdn2.microsoft.com/en-us/library/aa220971(office.11).aspx
(should also work with 2007)
0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 
Steve KrileAuthor Commented:
These links are great, and I can sense it's where I need to be, but darnit if I'm not missing something simple.  I'm used to (from the world of Excel) putting a Sub in my project module, assigning that sub to an object's click event or whatever, and that's it.  However, that approach doesn't seem to be working in PowerPoint.  What very basic thing am I missing here?
0
 
GlennaShawCommented:
Duh, sorry brain's slow.  Insert any object on the slide, then assign the Action Settings to run the macro.
Jusr right click on the object, click Action Settings...
0
 
Steve KrileAuthor Commented:
Right.  So, did that.  Put a rectangle on it and set it's action to AddMotionPath().  Run I view the slide and click on the rectagle, a star flashes in the top corner then that's it.  I don't see it move, and clicking advances the slide.

Sub AddMotionPath()

    Dim shpNew As Shape
    Dim effNew As Effect
    Dim aniMotion As AnimationBehavior

    Set shpNew = ActivePresentation.Slides(1).Shapes.AddShape(Type:=msoShape5pointStar, Left:=0, Top:=0, Width:=100, Height:=100)
    Set effNew = ActivePresentation.Slides(1).TimeLine.MainSequence.AddEffect(Shape:=shpNew, effectId:=msoAnimEffectCustom, Trigger:=msoAnimTriggerWithPrevious)
    Set aniMotion = effNew.Behaviors.Add(msoAnimTypeMotion)

    With aniMotion.MotionEffect
        .FromX = 0
        .FromY = 0
        .ToX = 500
        .ToY = 500
    End With

End Sub

Is this a code problem, or am I implementing this incorrectly?  PP 2003 btw.
0
 
GlennaShawCommented:
There's a problem with the example, see: http://www.mcse.ms/message637367.html
Also, using VML motion path is the recommended method, see: http://www.mcse.ms/message1659857.html
The VML motion path programming is a bit over my head, perhaps you should post in the VB zone.
0
 
Steve KrileAuthor Commented:
wow.  Good to see the clarifications and this does answer my question...so, thanks for the links.
0
 
Steve KrileAuthor Commented:
Here is the code that will work:

Sub AddMotionPath()

Dim shpNew As Shape
Dim effNew As Effect
Dim aniMotion As AnimationBehavior

Set shpNew = ActivePresentation.Slides(1).Shapes _
.AddShape(Type:=msoShape5pointStar, Left:=0, _
Top:=0, Width:=100, Height:=100)

Set effNew = ActivePresentation.Slides(1).TimeLine.MainSequence _
.AddEffect(Shape:=shpNew, effectId:=msoAnimEffectCustom, _
Trigger:=msoAnimTriggerWithPrevious)

Set aniMotion = effNew.Behaviors.Add(msoAnimTypeMotion)

effNew.Timing.Duration = 1
With aniMotion.MotionEffect
.FromX = 0
.FromY = 0
.ToX = 0.5
.ToY = 0.5
End With
   

End Sub
0
 
Steve KrileAuthor Commented:
This is more along the line of what I was looking for:

[ Shapes("Oval 9") is an object on my first slide ]

This creates a nice curvy path for my oval to follow.

Sub AddMotionPath()

    Dim shpNew As Shape
    Dim effNew As Effect
    Dim aniMotion As AnimationBehavior
   
    Set shpNew = ActivePresentation.Slides(1).Shapes("Oval 9")
   
    Set effNew = ActivePresentation.Slides(1).TimeLine.MainSequence _
                .AddEffect(Shape:=shpNew, effectId:=msoAnimEffectCustom, _
                Trigger:=msoAnimTriggerWithPrevious)
   
    Set aniMotion = effNew.Behaviors.Add(msoAnimTypeMotion)
    effNew.Timing.Duration = 10
    With aniMotion.MotionEffect
       .Path = "M 4.72222E-6 5.18519E-6 " & _
                "C 0.00034 0.09052 0.00069 0.18126 0.03802 0.18889 " & _
                "C 0.07534 0.19653 0.22291 0.00393 0.22378 0.04607 " & _
                "C 0.22465 0.0882 0.03645 0.35232 0.04288 0.44121 " & _
                "C 0.0493 0.5301 0.15555 0.55464 0.2618 0.5794 E"
    End With
End Sub
0
 
GlennaShawCommented:
I am soooo glad you got that, because those path coordinates are beyond me :-)
0
 
Steve KrileAuthor Commented:
yeah, basically i don't know what they all mean...so, it's a trial and error thing  :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now