public void AddAppearDisappearAnimation(Shape sh) { Sequence sequence = _slide.TimeLine.MainSequence; Effect effectAppear = sequence.AddEffect(sh, MsoAnimEffect.msoAnimEffectAppear, MsoAnimateByLevel.msoAnimateLevelNone, MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectAppear.Timing.Duration = 0; Effect effectDisappear = sequence.AddEffect(sh, MsoAnimEffect.msoAnimEffectAppear, MsoAnimateByLevel.msoAnimateLevelNone, MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectDisappear.Exit = Office.MsoTriState.msoTrue; effectDisappear.Timing.Duration = 0; }
public Effect SetShapeAsClickTriggered(Shape shape, int clickNumber, MsoAnimEffect effect) { Effect addedEffect; Sequence mainSequence = _slide.TimeLine.MainSequence; Effect nextClickEffect = mainSequence.FindFirstAnimationForClick(clickNumber + 1); Effect previousClickEffect = mainSequence.FindFirstAnimationForClick(clickNumber); bool hasClicksAfter = nextClickEffect != null; bool hasClickBefore = previousClickEffect != null; if (hasClicksAfter) { addedEffect = InsertAnimationBeforeExisting(shape, nextClickEffect, effect); } else if (hasClickBefore) { addedEffect = AddShapeAsLastAutoplaying(shape, effect); } else { addedEffect = mainSequence.AddEffect(shape, effect); } return(addedEffect); }
/// <summary> /// Zoom out from initial shape to the full slide. /// Returns the final disappear effect for initialShape. /// </summary> public static PowerPoint.Effect AddZoomOutMotionAnimation(PowerPointSlide animationSlide, PowerPoint.Shape initialShape, PowerPoint.MsoAnimTriggerType trigger) { float initialX = (initialShape.Left + (initialShape.Width) / 2); float initialY = (initialShape.Top + (initialShape.Height) / 2); float initialWidth = initialShape.Width; float initialHeight = initialShape.Height; float finalX = PowerPointPresentation.Current.SlideWidth / 2; float finalY = PowerPointPresentation.Current.SlideHeight / 2; float finalWidth = PowerPointPresentation.Current.SlideWidth; float finalHeight = PowerPointPresentation.Current.SlideHeight; float duration = 0.4f; AddMotionAnimation(animationSlide, initialShape, initialX, initialY, finalX, finalY, duration, ref trigger); AddResizeAnimation(animationSlide, initialShape, initialWidth, initialHeight, finalWidth, finalHeight, duration, ref trigger); Sequence sequence = animationSlide.TimeLine.MainSequence; Effect effectDisappear = sequence.AddEffect(initialShape, PowerPoint.MsoAnimEffect.msoAnimEffectFade, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectDisappear.Exit = Office.MsoTriState.msoTrue; effectDisappear.Timing.Duration = 0.01f; return(effectDisappear); }
/// <summary> /// Preloads a shape within the slide to reduce lag. Call after the animations for the shape have been created. /// </summary> public static void PreloadShape(PowerPointSlide animationSlide, PowerPoint.Shape shape, bool addCoverImage = true) { // The cover image is used to cover the screen while the preloading happens behind the cover image. PowerPoint.Shape coverImage = null; if (addCoverImage) { coverImage = shape.Duplicate()[1]; coverImage.Left = shape.Left; coverImage.Top = shape.Top; animationSlide.RemoveAnimationsForShape(coverImage); } float originalWidth = shape.Width; float originalHeight = shape.Height; float originalLeft = shape.Left; float originalTop = shape.Top; // fit the shape exactly in the screen for preloading. float scaleRatio = Math.Min(PowerPointPresentation.Current.SlideWidth / shape.Width, PowerPointPresentation.Current.SlideHeight / shape.Height); animationSlide.RelocateShapeWithoutPath(shape, 0, 0, shape.Width * scaleRatio, shape.Height * scaleRatio); MsoAnimTriggerType trigger = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious; Effect effectMotion = AddMotionAnimation(animationSlide, shape, shape.Left, shape.Top, originalLeft + (originalWidth - shape.Width) / 2, originalTop + (originalHeight - shape.Height) / 2, 0, ref trigger); Effect effectResize = AddResizeAnimation(animationSlide, shape, shape.Width, shape.Height, originalWidth, originalHeight, 0, ref trigger); // Make "cover" image disappear after preload. PowerPoint.Effect effectDisappear = null; if (addCoverImage) { Sequence sequence = animationSlide.TimeLine.MainSequence; effectDisappear = sequence.AddEffect(coverImage, PowerPoint.MsoAnimEffect.msoAnimEffectFade, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectDisappear.Exit = Office.MsoTriState.msoTrue; effectDisappear.Timing.Duration = 0.01f; } int firstEffectIndex = animationSlide.IndexOfFirstEffect(shape); // Move the animations to just before the index of the first effect. if (effectDisappear != null) { effectDisappear.MoveTo(firstEffectIndex); } if (effectResize != null) { effectResize.MoveTo(firstEffectIndex); } if (effectMotion != null) { effectMotion.MoveTo(firstEffectIndex); } }
private static void AddTriggerEffect(Shape triggerShape, List <Shape> shapesToAnimate, MsoAnimEffect effect, Sequence sequence) { // Add Entrance Effect for (int i = 0; i < shapesToAnimate.Count; i++) { Shape animationShape = shapesToAnimate[i]; MsoAnimTriggerType triggerType; // The first shape will be triggered by the click to appear if (i == 0) { triggerType = MsoAnimTriggerType.msoAnimTriggerOnShapeClick; sequence.AddTriggerEffect(animationShape, effect, triggerType, triggerShape); } // Rest of the shapes will appear with the first shape else { triggerType = MsoAnimTriggerType.msoAnimTriggerWithPrevious; sequence.AddEffect(shapesToAnimate[i], effect, MsoAnimateByLevel.msoAnimateLevelNone, MsoAnimTriggerType.msoAnimTriggerWithPrevious); } } // Add Exit Effect to Shapes for (int i = 0; i < shapesToAnimate.Count; i++) { Shape animationShape = shapesToAnimate[i]; MsoAnimTriggerType triggerType; Effect effectInSequence; // The first shape will be triggered by the click to disappear if (i == 0) { triggerType = MsoAnimTriggerType.msoAnimTriggerOnShapeClick; effectInSequence = sequence.AddTriggerEffect(animationShape, effect, triggerType, triggerShape); } // Rest of the shapes will disappear with the first shape else { triggerType = MsoAnimTriggerType.msoAnimTriggerWithPrevious; effectInSequence = sequence.AddEffect(shapesToAnimate[i], effect, MsoAnimateByLevel.msoAnimateLevelNone, MsoAnimTriggerType.msoAnimTriggerWithPrevious); } effectInSequence.Exit = Microsoft.Office.Core.MsoTriState.msoTrue; } }
static void Main(string[] args) { // animates the shapes, and runs the slide show. Application ppApp = new Application(); // Create a new PowerPoint presentation. Presentation objPres = ppApp.Presentations.Add(MsoTriState.msoTrue); // Add a slide to the presentation. _Slide objSlide = objPres.Slides.Add (1, PpSlideLayout.ppLayoutBlank); // Place two shapes on the slide. Microsoft.Office.Interop.PowerPoint.Shape objSquareShape = objSlide.Shapes.AddShape (MsoAutoShapeType.msoShapeRectangle, 0, 0, 100, 100); Microsoft.Office.Interop.PowerPoint.Shape objTriangleShape = objSlide.Shapes.AddShape (MsoAutoShapeType.msoShapeRightTriangle, 0, 150, 100, 100); // Add an animation sequence. Sequence objSequence = objSlide.TimeLine.InteractiveSequences.Add(1); // Add text to the shapes. objSquareShape.TextFrame.TextRange.Text = "Click Me! "; objTriangleShape.TextFrame.TextRange.Text = "Me Too! "; // Animate the shapes. objSequence.AddEffect(objSquareShape, MsoAnimEffect.msoAnimEffectPathStairsDown, MsoAnimateByLevel.msoAnimateLevelNone, MsoAnimTriggerType.msoAnimTriggerOnShapeClick, 1); objSequence.AddEffect(objTriangleShape, MsoAnimEffect.msoAnimEffectPathHorizontalFigure8, MsoAnimateByLevel.msoAnimateLevelNone, MsoAnimTriggerType.msoAnimTriggerOnShapeClick, 1); }
public static void MakeShapeViewTimeInvisible(Shape shape, Slide curSlide) { Sequence sequence = curSlide.TimeLine.MainSequence; Effect effectAppear = sequence.AddEffect(shape, MsoAnimEffect.msoAnimEffectAppear, MsoAnimateByLevel.msoAnimateLevelNone, MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectAppear.Timing.Duration = 0; Effect effectDisappear = sequence.AddEffect(shape, MsoAnimEffect.msoAnimEffectAppear, MsoAnimateByLevel.msoAnimateLevelNone, MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectDisappear.Exit = MsoTriState.msoTrue; effectDisappear.Timing.Duration = 0; effectAppear.MoveTo(1); effectDisappear.MoveTo(2); }
/// <summary> /// Creates a cover image from a copy of the shape to obstruct the viewer while preloading images in the background. /// </summary> public static void DuplicateAsCoverImage(PowerPointSlide animationSlide, PowerPoint.Shape shape) { Shape coverImage = shape.Duplicate()[1]; coverImage.Left = shape.Left; coverImage.Top = shape.Top; animationSlide.RemoveAnimationsForShape(coverImage); Sequence sequence = animationSlide.TimeLine.MainSequence; Effect effectDisappear = sequence.AddEffect(coverImage, PowerPoint.MsoAnimEffect.msoAnimEffectFade, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectDisappear.Exit = Office.MsoTriState.msoTrue; effectDisappear.Timing.Duration = 0.01f; effectDisappear.MoveTo(1); }