- mattoFeatured Creator
- Posts : 81
Join date : 2022-08-11
Location : Japan
Working with motion paths in VBA... not exactly fun...
Sat Jan 07, 2023 11:52 pm
Recently, I wasted an entire day trying to figure out how to program motion paths in VBA...
How do you do it?
The short answer is... it's best not to...
I'm paraphrasing from someone else, but a motion path is basically a collection of coordinates for a Line or Bezier curve (for PowerPoint purposes). The values are fractions of the slide dimensions. So that means that values can differ depending on the size of your slide.
What does that gibberish mean? It means that it takes complicated math to program a motion path.
So...
RATHER THAN THAT
First, make a shape and apply your motion path as you would normally in PowerPoint. Then use this code to ask for the values of that motion path. If the motion path isn't the very first animation in the animation pane, then change MainSequence(1) to MainSequence(2) or MainSequence(3) or MainSequence(4), etc, to reflect where it is.
You can also find the default value of motion path effects by doing something like this. Here is an example for a motion path selected to rise up.
Your motion path value for this example should be:
So to apply that to your desired shape, you can do something like
Another alternative is to simply copy and paste the desired animation from one shape to another.
It's dead simple. It's basically using the animation painter.
How do you do it?
The short answer is... it's best not to...
I'm paraphrasing from someone else, but a motion path is basically a collection of coordinates for a Line or Bezier curve (for PowerPoint purposes). The values are fractions of the slide dimensions. So that means that values can differ depending on the size of your slide.
What does that gibberish mean? It means that it takes complicated math to program a motion path.
So...
RATHER THAN THAT
First, make a shape and apply your motion path as you would normally in PowerPoint. Then use this code to ask for the values of that motion path. If the motion path isn't the very first animation in the animation pane, then change MainSequence(1) to MainSequence(2) or MainSequence(3) or MainSequence(4), etc, to reflect where it is.
- Code:
Debug.Print ActivePresentation.Slides(1).TimeLine.MainSequence(1).Behaviors(1).MotionEffect.Path
You can also find the default value of motion path effects by doing something like this. Here is an example for a motion path selected to rise up.
- Code:
Dim SHAPE1 As Shape
Dim EFFECT1 As Effect
Set SHAPE1 = ActivePresentation.Slides(1).Shapes("ENTER YOUR SHAPE NAME HERE")
Set EFFECT1 = ActivePresentation.Slides(1).TimeLine.MainSequence _
.AddEffect(Shape:=SHAPE1, effectId:=msoAnimEffectPathUp, _
Trigger:=msoAnimTriggerWithPrevious)
Debug.Print EFFECT1.Behaviors(1).MotionEffect.Path
Your motion path value for this example should be:
- Code:
M 0 0 L 0 -0.025 E
So to apply that to your desired shape, you can do something like
- Code:
Dim SHAPE1 As Shape
Dim EFFECT1 As Effect
Dim ANIMOTION As AnimationBehavior
Set SHAPE1 = ActivePresentation.Slides(1).Shapes("ENTER YOUR SHAPE NAME")
Set EFFECT1 = ActivePresentation.Slides(1).TimeLine.MainSequence _
.AddEffect(Shape:=SHAPE1, effectId:=msoAnimEffectPathUp, _
Trigger:=msoAnimTriggerWithPrevious)
Set ANIMOTION = EFFECT1.Behaviors(1)
With ANIMOTION.MotionEffect
.Path = "M 0 0 L 0 -0.025 E"
End With
With EFFECT1
.Timing.Duration = 2
.Timing.SmoothStart = msoTrue
.Timing.SmoothEnd = msoTrue
.Timing.Accelerate = 1
.Timing.Decelerate = 1
.Timing.RepeatCount = 999
.Timing.AutoReverse = msoCTrue
End With
Another alternative is to simply copy and paste the desired animation from one shape to another.
It's dead simple. It's basically using the animation painter.
- Code:
ActivePresentation.Slides(1).Shapes("ENTER SHAPE NAME HERE").PickupAnimation
- Code:
ActivePresentation.Slides(1).Shapes("ENTER SHAPE NAME HERE").ApplyAnimation
JadeJohnsonIndustries™ likes this post
Re: Working with motion paths in VBA... not exactly fun...
Mon Jan 09, 2023 6:28 pm
That Animation-Painter hack is actually really funny to me, as "Pick-Up" and "Apply" are actually also the default names for what you do to styles when you are utilising the Format-Painter, as per "PowerPoint Spice" herself!
JadeJohnsonIndustries™ likes this post
Re: Working with motion paths in VBA... not exactly fun...
Thu Jan 12, 2023 10:12 pm
I have messed with motion paths in VBA once before, and forgot all about the headache that entails! I'll have to dig around to see if I can still find it and see if anything makes sense again and I could see if I could help. I think if I remember correctly that motion paths aren't based off points like shape attribute measurements, but based off percentage of the slide from 0 - 100 (or 1?) Send me a PM to remind me to look into this if I haven't got back to you in a week or something
- mattoFeatured Creator
- Posts : 81
Join date : 2022-08-11
Location : Japan
Re: Working with motion paths in VBA... not exactly fun...
Fri Jan 13, 2023 5:50 am
That's ok. I was just venting my frustration.
Permissions in this forum:
You cannot reply to topics in this forum
|
|