private static void ConvertToPictureForShape(PowerPoint.Shape shape) { float rotation = 0; try { rotation = shape.Rotation; shape.Rotation = 0; } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "Chart cannot be rotated."); } shape.Copy(); float x = shape.Left; float y = shape.Top; float width = shape.Width; float height = shape.Height; shape.Delete(); var pic = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; pic.Left = x + (width - pic.Width) / 2; pic.Top = y + (height - pic.Height) / 2; pic.Rotation = rotation; pic.Select(); }
public static void AddFrameMotionAnimation(PowerPointSlide animationSlide, PowerPoint.Shape initialShape, PowerPoint.Shape finalShape, float duration) { float initialX = (initialShape.Left + (initialShape.Width) / 2); float initialY = (initialShape.Top + (initialShape.Height) / 2); float initialRotation = initialShape.Rotation; float initialWidth = initialShape.Width; float initialHeight = initialShape.Height; float initialFont = 0.0f; float finalX = (finalShape.Left + (finalShape.Width) / 2); float finalY = (finalShape.Top + (finalShape.Height) / 2); float finalRotation = finalShape.Rotation; float finalWidth = finalShape.Width; float finalHeight = finalShape.Height; float finalFont = 0.0f; if (initialShape.HasTextFrame == Office.MsoTriState.msoTrue && (initialShape.TextFrame.HasText == Office.MsoTriState.msoTriStateMixed || initialShape.TextFrame.HasText == Office.MsoTriState.msoTrue) && initialShape.TextFrame.TextRange.Font.Size != finalShape.TextFrame.TextRange.Font.Size) { finalFont = finalShape.TextFrame.TextRange.Font.Size; initialFont = initialShape.TextFrame.TextRange.Font.Size; } int numFrames = (int)(duration / 0.04f); numFrames = (numFrames > 30) ? 30 : numFrames; float incrementWidth = ((finalWidth / initialWidth) - 1.0f) / numFrames; float incrementHeight = ((finalHeight / initialHeight) - 1.0f) / numFrames; float incrementRotation = PowerPointLabsGlobals.GetMinimumRotation(initialRotation, finalRotation) / numFrames; float incrementLeft = (finalX - initialX) / numFrames; float incrementTop = (finalY - initialY) / numFrames; float incrementFont = (finalFont - initialFont) / numFrames; AddFrameAnimationEffects(animationSlide, initialShape, incrementLeft, incrementTop, incrementWidth, incrementHeight, incrementRotation, incrementFont, duration, numFrames); }
public static void AddAutoAnimation() { try { //Get References of current and next slides var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; if (currentSlide == null || currentSlide.Index == PowerPointPresentation.Current.SlideCount) { System.Windows.Forms.MessageBox.Show("Please select the correct slide", "Unable to Add Animations"); return; } PowerPointSlide nextSlide = PowerPointPresentation.Current.Slides[currentSlide.Index]; if (!GetMatchingShapeDetails(currentSlide, nextSlide)) { System.Windows.Forms.MessageBox.Show("No matching Shapes were found on the next slide", "Animation Not Added"); return; } AddCompleteAnimations(currentSlide, nextSlide); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddAnimationButtonClick"); Views.ErrorDialogWrapper.ShowDialog("PowerPointLabs", e.Message, e); } }
public static void AddSpotlightEffect() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; PowerPoint.ShapeRange selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; var addedSlide = currentSlide.CreateSpotlightSlide() as PowerPointSpotlightSlide; List <PowerPoint.Shape> spotlightShapes = new List <PowerPoint.Shape>(); addedSlide.DeleteShapesWithPrefix("SpotlightShape"); foreach (PowerPoint.Shape spotShape in selectedShapes) { addedSlide.DeleteShapesWithPrefix(spotShape.Name); PreFormatShapeOnCurrentSlide(spotShape); PowerPoint.Shape spotlightShape = addedSlide.CreateSpotlightShape(spotShape); CreateSpotlightDuplicate(spotlightShape); spotlightShapes.Add(spotlightShape); PostFormatShapeOnCurrentSlide(currentSlide, spotShape); } addedSlide.PrepareForSpotlight(); addedSlide.AddSpotlightEffect(spotlightShapes); currentSlide.DeleteShapesWithPrefix("SpotlightShape"); PowerPointPresentation.Current.AddAckSlide(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "SpotlightBtnClick"); throw; } }
public static void AddAnimationInSlide() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; var selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange as PowerPoint.ShapeRange; currentSlide.RemoveAnimationsForShapes(selectedShapes.Cast <PowerPoint.Shape>().ToList()); if (!isHighlightBullets && !isHighlightTextFragments) { FormatInSlideAnimateShapes(selectedShapes); } if (selectedShapes.Count == 1) { InSlideAnimateSingleShape(currentSlide, selectedShapes[1]); } else { InSlideAnimateMultiShape(currentSlide, selectedShapes); } if (!isHighlightBullets && !isHighlightTextFragments) { Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview"); PowerPointPresentation.Current.AddAckSlide(); } } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddAnimationInSlide"); throw; } }
public static Bitmap GetCutOutShapeMenuImage(Office.IRibbonControl control) { try { return(new Bitmap(Properties.Resources.CutOutShapeMenu)); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "GetCutOutShapeMenuImage"); throw; } }
public static System.Drawing.Bitmap GetConvertToPicMenuImage(Office.IRibbonControl control) { try { return(new System.Drawing.Bitmap(Properties.Resources.ConvertToPicture)); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "GetConvertToPicMenuImage"); throw; } }
private static PowerPoint.Effect AddRotationAnimation(PowerPointSlide animationSlide, PowerPoint.Shape animationShape, float initialRotation, float finalRotation, float duration, ref PowerPoint.MsoAnimTriggerType trigger) { if (finalRotation != initialRotation) { PowerPoint.Effect effectRotate = animationSlide.TimeLine.MainSequence.AddEffect(animationShape, PowerPoint.MsoAnimEffect.msoAnimEffectSpin, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, trigger); PowerPoint.AnimationBehavior rotate = effectRotate.Behaviors[1]; effectRotate.Timing.Duration = duration; effectRotate.EffectParameters.Amount = PowerPointLabsGlobals.GetMinimumRotation(initialRotation, finalRotation); trigger = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious; return(effectRotate); } return(null); }
public static void AddHighlightedTextFragments() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; PowerPoint.ShapeRange selectedShapes = null; Office.TextRange2 selectedText = null; //Get shapes to consider for animation switch (userSelection) { case HighlightTextSelection.kShapeSelected: return; case HighlightTextSelection.kTextSelected: selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; selectedText = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText(); break; case HighlightTextSelection.kNoneSelected: return; default: return; } if (selectedText.Length <= 0) { return; } if (selectedShapes.Count != 1) { return; } List <PowerPoint.Shape> selectionToAnimate = GetShapesFromLinesInText(currentSlide, selectedText, selectedShapes[1]); GroupShapesForAnimation(selectionToAnimate); List <PowerPoint.Shape> shapesToAnimate = GetShapesToAnimate(currentSlide); SelectShapes(shapesToAnimate); RunAnimateInSlide(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddHighlightedTextFragments"); throw; } }
//Shape dimensions should match the slide dimensions and the shape should be within the slide private static PowerPoint.Shape GetBestFitShape(PowerPointSlide currentSlide, PowerPoint.Shape zoomShape) { zoomShape.Copy(); PowerPoint.Shape zoomShapeCopy = currentSlide.Shapes.Paste()[1]; zoomShapeCopy.LockAspectRatio = Office.MsoTriState.msoFalse; if (zoomShape.Width > zoomShape.Height) { zoomShapeCopy.Width = zoomShape.Width; zoomShapeCopy.Height = PowerPointPresentation.Current.SlideHeight * zoomShapeCopy.Width / PowerPointPresentation.Current.SlideWidth; } else { zoomShapeCopy.Height = zoomShape.Height; zoomShapeCopy.Width = PowerPointPresentation.Current.SlideWidth * zoomShapeCopy.Height / PowerPointPresentation.Current.SlideHeight; } PowerPointLabsGlobals.CopyShapePosition(zoomShape, ref zoomShapeCopy); if (zoomShapeCopy.Width > PowerPointPresentation.Current.SlideWidth) { zoomShapeCopy.Width = PowerPointPresentation.Current.SlideWidth; } if (zoomShapeCopy.Height > PowerPointPresentation.Current.SlideHeight) { zoomShapeCopy.Height = PowerPointPresentation.Current.SlideHeight; } if (zoomShapeCopy.Left < 0) { zoomShapeCopy.Left = 0; } if (zoomShapeCopy.Left + zoomShapeCopy.Width > PowerPointPresentation.Current.SlideWidth) { zoomShapeCopy.Left = PowerPointPresentation.Current.SlideWidth - zoomShapeCopy.Width; } if (zoomShapeCopy.Top < 0) { zoomShapeCopy.Top = 0; } if (zoomShapeCopy.Top + zoomShapeCopy.Height > PowerPointPresentation.Current.SlideHeight) { zoomShapeCopy.Top = PowerPointPresentation.Current.SlideHeight - zoomShapeCopy.Height; } return(zoomShapeCopy); }
//Return picture copy of next slide where shapes with exit animations have been deleted private static PowerPoint.Shape GetNextSlidePictureWithoutBackground(PowerPointSlide currentSlide, PowerPointSlide nextSlide, out PowerPoint.Shape pictureOnNextSlide) { Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(nextSlide.Index); List <PowerPoint.Shape> shapesOnNextSlide = new List <PowerPoint.Shape>(); foreach (PowerPoint.Shape sh in nextSlide.Shapes) { if (!nextSlide.HasEntryAnimation(sh) && !Graphics.IsHidden(sh)) { shapesOnNextSlide.Add(sh); } } var copiedShapes = new List <PowerPoint.Shape>(); foreach (PowerPoint.Shape sh in shapesOnNextSlide) { sh.Copy(); var shapeCopy = nextSlide.Shapes.Paste()[1]; PowerPointLabsGlobals.CopyShapeAttributes(sh, ref shapeCopy); copiedShapes.Add(shapeCopy); } SelectAllShape(copiedShapes); PowerPoint.Selection sel = Globals.ThisAddIn.Application.ActiveWindow.Selection; PowerPoint.Shape shapeGroup = null; if (sel.ShapeRange.Count > 1) { shapeGroup = sel.ShapeRange.Group(); } else { shapeGroup = sel.ShapeRange[1]; } shapeGroup.Copy(); pictureOnNextSlide = nextSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; PowerPointLabsGlobals.CopyShapePosition(shapeGroup, ref pictureOnNextSlide); shapeGroup.Delete(); pictureOnNextSlide.Copy(); PowerPoint.Shape slidePicture = currentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; return(slidePicture); }
//Set position, size and animations of the previous slide copy private static void PreparePreviousSlidePicture(PowerPointSlide currentSlide, PowerPoint.Shape selectedShape, ref PowerPoint.Shape previousSlidePicture) { previousSlidePicture.LockAspectRatio = Office.MsoTriState.msoTrue; if (selectedShape.Width > selectedShape.Height) { previousSlidePicture.Height = selectedShape.Height; } else { previousSlidePicture.Width = selectedShape.Width; } PowerPointLabsGlobals.CopyShapePosition(selectedShape, ref previousSlidePicture); selectedShape.Visible = Office.MsoTriState.msoFalse; previousSlidePicture.Name = "PPTZoomOutShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); }
//Set position, size and animations of the next slide copy private static void PrepareNextSlidePicture(PowerPointSlide currentSlide, PowerPoint.Shape selectedShape, ref PowerPoint.Shape nextSlidePicture) { nextSlidePicture.LockAspectRatio = Office.MsoTriState.msoTrue; if (selectedShape.Width > selectedShape.Height) { nextSlidePicture.Height = selectedShape.Height; } else { nextSlidePicture.Width = selectedShape.Width; } PowerPointLabsGlobals.CopyShapePosition(selectedShape, ref nextSlidePicture); selectedShape.Visible = Office.MsoTriState.msoFalse; nextSlidePicture.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); PowerPoint.Effect effectAppear = currentSlide.TimeLine.MainSequence.AddEffect(nextSlidePicture, PowerPoint.MsoAnimEffect.msoAnimEffectFade, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerOnPageClick); effectAppear.Timing.Duration = 0.50f; }
public static void AddZoomToArea() { if (!IsSelectingShapes()) { return; } try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide; DeleteExistingZoomToAreaSlides(currentSlide); currentSlide.Name = "PPTLabsZoomToAreaSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); var selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; var zoomRectangles = ReplaceWithZoomRectangleImages(currentSlide, selectedShapes); MakeInvisible(zoomRectangles); List <PowerPoint.Shape> editedSelectedShapes = GetEditedShapesForZoomToArea(currentSlide, zoomRectangles); var addedSlides = AddMultiSlideZoomToArea(currentSlide, editedSelectedShapes); if (!multiSlideZoomChecked) { Graphics.SquashSlides(addedSlides); } MakeVisible(zoomRectangles); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(currentSlide.Index); PowerPointPresentation.Current.AddAckSlide(); // Always call ReleaseComObject and GC.Collect after shape deletion to prevent shape corruption after undo. System.Runtime.InteropServices.Marshal.ReleaseComObject(selectedShapes); GC.Collect(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddZoomToArea"); ErrorDialogWrapper.ShowDialog("Error when adding zoom to area", "An error occurred when adding zoom to area.", e); throw; } }
private static PowerPoint.Shape GetStepBackWithoutBackgroundShapeToZoom(PowerPointSlide currentSlide, PowerPointSlide addedSlide, PowerPointSlide previousSlide) { Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index); var copiedShapes = new List <PowerPoint.Shape>(); foreach (PowerPoint.Shape sh in previousSlide.Shapes) { if (!previousSlide.HasExitAnimation(sh) && !Graphics.IsHidden(sh)) { sh.Copy(); PowerPoint.Shape shapeCopy = addedSlide.Shapes.Paste()[1]; PowerPointLabsGlobals.CopyShapeAttributes(sh, ref shapeCopy); copiedShapes.Add(shapeCopy); } } SelectAllShape(copiedShapes); PowerPoint.Selection sel = Globals.ThisAddIn.Application.ActiveWindow.Selection; PowerPoint.Shape shapeGroup = null; if (sel.ShapeRange.Count > 1) { shapeGroup = sel.ShapeRange.Group(); } else { shapeGroup = sel.ShapeRange[1]; } shapeGroup.Copy(); PowerPoint.Shape previousSlidePicture = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; PowerPointLabsGlobals.CopyShapePosition(shapeGroup, ref previousSlidePicture); previousSlidePicture.Name = "PPTZoomOutShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); shapeGroup.Delete(); return(previousSlidePicture); }
public static void AddHighlightBulletsBackground() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; currentSlide.Name = "PPTLabsHighlightBulletsSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); PowerPoint.ShapeRange selectedShapes = null; Office.TextRange2 selectedText = null; //Get shapes to consider for animation List <PowerPoint.Shape> shapesToUse = null; switch (userSelection) { case HighlightBackgroundSelection.kShapeSelected: selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; shapesToUse = GetShapesToUse(currentSlide, selectedShapes); break; case HighlightBackgroundSelection.kTextSelected: selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; selectedText = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText(); shapesToUse = GetShapesToUse(currentSlide, selectedShapes); break; case HighlightBackgroundSelection.kNoneSelected: currentSlide.DeleteIndicator(); currentSlide.DeleteShapesWithPrefix("PPTLabsHighlightBackgroundShape"); shapesToUse = GetAllUsableShapesInSlide(currentSlide); break; default: break; } Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(currentSlide.Index); if (shapesToUse == null || shapesToUse.Count == 0) { return; } SelectOldShapesToAnimate(currentSlide, shapesToUse); bool newShapesAdded = AddNewShapesToAnimate(currentSlide, shapesToUse, selectedText); if (newShapesAdded) { bool oldValue = AnimateInSlide.frameAnimationChecked; AnimateInSlide.frameAnimationChecked = false; AnimateInSlide.isHighlightBullets = true; AnimateInSlide.AddAnimationInSlide(); AnimateInSlide.frameAnimationChecked = oldValue; PowerPointPresentation.Current.AddAckSlide(); } Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddHighlightBulletsBackground"); throw; } }
public static void ReloadAutoAnimation() { try { var selectedSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; PowerPointSlide currentSlide = null, animatedSlide = null, nextSlide = null; if (selectedSlide.Name.StartsWith("PPSlideAnimated")) { nextSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index]; currentSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 2]; animatedSlide = selectedSlide; ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } else if (selectedSlide.Name.StartsWith("PPSlideStart")) { animatedSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index]; nextSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index + 1]; currentSlide = selectedSlide; ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } else if (selectedSlide.Name.StartsWith("PPSlideEnd")) { animatedSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 2]; currentSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 3]; nextSlide = selectedSlide; ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } else if (selectedSlide.Name.StartsWith("PPSlideMulti")) { if (selectedSlide.Index > 2) { animatedSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 2]; currentSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index - 3]; nextSlide = selectedSlide; if (animatedSlide.Name.StartsWith("PPSlideAnimated")) { ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } } if (selectedSlide.Index < PowerPointPresentation.Current.SlideCount - 1) { animatedSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index]; nextSlide = PowerPointPresentation.Current.Slides[selectedSlide.Index + 1]; currentSlide = selectedSlide; if (animatedSlide.Name.StartsWith("PPSlideAnimated")) { ManageSlidesForReload(currentSlide, nextSlide, animatedSlide); } } } else { System.Windows.Forms.MessageBox.Show("The current slide was not added by PowerPointLabs Auto Animate", "Error"); } } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "ReloadAutoAnimation"); Views.ErrorDialogWrapper.ShowDialog("PowerPointLabs", e.Message, e); } }
public static void AddHighlightBulletsText() { try { var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide; PowerPoint.ShapeRange selectedShapes = null; Office.TextRange2 selectedText = null; //Get shapes to consider for animation List <PowerPoint.Shape> shapesToUse = null; switch (userSelection) { case HighlightTextSelection.kShapeSelected: selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; shapesToUse = GetShapesToUse(currentSlide, selectedShapes); break; case HighlightTextSelection.kTextSelected: selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; selectedText = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText(); shapesToUse = GetShapesToUse(currentSlide, selectedShapes); break; case HighlightTextSelection.kNoneSelected: currentSlide.DeleteIndicator(); currentSlide.DeleteShapesWithPrefix("PPTLabsHighlightBackgroundShape"); shapesToUse = GetAllUsableShapesInSlide(currentSlide); break; default: break; } if (currentSlide.Name.Contains("PPTLabsHighlightBulletsSlide")) { ProcessExistingHighlightSlide(currentSlide, shapesToUse); } if (shapesToUse == null || shapesToUse.Count == 0) { return; } currentSlide.Name = "PPTLabsHighlightBulletsSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); PowerPoint.Sequence sequence = currentSlide.TimeLine.MainSequence; bool isFirstShape = IsFirstShape(currentSlide); foreach (PowerPoint.Shape sh in shapesToUse) { if (!sh.Name.Contains("HighlightTextShape")) { sh.Name = "HighlightTextShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); } //Add Font Appear effect for all paragraphs within shape int currentIndex = sequence.Count; sequence.AddEffect(sh, PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor, PowerPoint.MsoAnimateByLevel.msoAnimateTextByFifthLevel, PowerPoint.MsoAnimTriggerType.msoAnimTriggerOnPageClick); var appearEffects = AsList(sequence, currentIndex + 1, sequence.Count + 1); //Add Font Disappear effect for all paragraphs within shape currentIndex = sequence.Count; sequence.AddEffect(sh, PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor, PowerPoint.MsoAnimateByLevel.msoAnimateTextByFifthLevel, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious); var disappearEffects = AsList(sequence, currentIndex + 1, sequence.Count + 1); //Remove effects for paragraphs without bullet points var markedForRemoval = GetParagraphsToRemove(sh, selectedText); // assert appearEffects.Count == disappearEffects.Count; // assert markedForRemoval.Count <= appearEffects.Count; for (int i = markedForRemoval.Count - 1; i >= 0; --i) { // delete from back. int index = markedForRemoval[i]; appearEffects[index].Delete(); appearEffects.RemoveAt(index); disappearEffects[index].Delete(); disappearEffects.RemoveAt(index); } if (appearEffects.Count == 0) { continue; } RearrangeEffects(appearEffects, disappearEffects); FormatAppearEffects(appearEffects, isFirstShape); FormatDisappearEffects(disappearEffects); isFirstShape = false; } Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview"); PowerPointPresentation.Current.AddAckSlide(); } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddHighlightBulletsText"); throw; } }
public static void AddStepBackAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide, out PowerPointStepBackSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true) { try { if (currentSlide == null || currentSlide.Index == 1) { System.Windows.Forms.MessageBox.Show("No previous slide is found. Please select the correct slide", "Unable to Add Animations"); addedSlide = null; return; } //Pick up the border and shadow style, to be applied to zoomed shape selectedShape.PickUp(); PrepareZoomShape(currentSlide, ref selectedShape); PowerPointSlide previousSlide = GetPreviousSlide(currentSlide, deletePreviouslyAdded); PowerPoint.Shape previousSlidePicture = null, shapeToZoom = null; currentSlide.HideIndicator(); if (backgroundZoomChecked) { previousSlidePicture = GetPreviousSlidePictureWithBackground(currentSlide, previousSlide); previousSlidePicture.Apply(); PreparePreviousSlidePicture(currentSlide, selectedShape, ref previousSlidePicture); addedSlide = (PowerPointStepBackSlide)previousSlide.CreateStepBackSlide(); addedSlide.DeleteAllShapes(); PowerPoint.Shape backgroundShape = null; shapeToZoom = GetStepBackWithBackgroundShapeToZoom(currentSlide, addedSlide, previousSlidePicture, out backgroundShape); shapeToZoom.Apply(); addedSlide.PrepareForStepBack(); addedSlide.AddStepBackAnimationBackground(shapeToZoom, backgroundShape, previousSlidePicture); } else { addedSlide = (PowerPointStepBackSlide)previousSlide.CreateStepBackSlide(); addedSlide.DeleteAllShapes(); shapeToZoom = GetStepBackWithoutBackgroundShapeToZoom(currentSlide, addedSlide, previousSlide); shapeToZoom.Apply(); shapeToZoom.Copy(); previousSlidePicture = currentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; previousSlidePicture.Apply(); PreparePreviousSlidePicture(currentSlide, selectedShape, ref previousSlidePicture); addedSlide.PrepareForStepBack(); addedSlide.AddStepBackAnimationNonBackground(shapeToZoom, previousSlidePicture); } currentSlide.ShowIndicator(); currentSlide.Transition.EntryEffect = PowerPoint.PpEntryEffect.ppEffectFadeSmoothly; currentSlide.Transition.Duration = 0.25f; Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index); Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview"); if (includeAckSlide) { PowerPointPresentation.Current.AddAckSlide(); } } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddStepBackAnimation"); ErrorDialogWrapper.ShowDialog("Error when adding step back animation", "An error occurred when adding step back animation.", e); throw; } }
/// <summary> /// This function will embed the auto generated speech to the current slide. /// File names of generated audios will be returned. /// </summary> /// <param name="slide">Current slide reference.</param> /// <returns>An array of auto generated audios' name.</returns> private static string[] EmbedSlideNotes(PowerPointSlide slide) { String folderPath = Path.GetTempPath() + TempFolderName; String fileNameSearchPattern = String.Format("Slide {0} Speech", slide.ID); Directory.CreateDirectory(folderPath); // TODO: // obviously deleting all audios in current slide may not a good idea, some lines of script // may still be the same. Check the line first before deleting, if the line has not been // changed, leave the audio. // to avoid duplicate records, delete all old audios in the current slide var audiosInCurrentSlide = Directory.GetFiles(folderPath); foreach (var audio in audiosInCurrentSlide) { if (audio.Contains(fileNameSearchPattern)) { try { File.Delete(audio); } catch (Exception e) { PowerPointLabsGlobals.Log("Error", "Failed to delete audio, it may be still playing. " + e.Message); } } } bool isSaveSuccessful = OutputSlideNotesToFiles(slide, folderPath); string[] audioFiles = null; if (isSaveSuccessful) { slide.DeleteShapesWithPrefix(SpeechShapePrefix); audioFiles = GetAudioFilePaths(folderPath, fileNameSearchPattern); for (int i = 0; i < audioFiles.Length; i++) { String fileName = audioFiles[i]; bool isOnClick = fileName.Contains("OnClick"); try { Shape audioShape = InsertAudioFileOnSlide(slide, fileName); audioShape.Name = String.Format("PowerPointLabs Speech {0}", i); slide.RemoveAnimationsForShape(audioShape); if (isOnClick) { slide.SetShapeAsClickTriggered(audioShape, i, MsoAnimEffect.msoAnimEffectMediaPlay); } else { slide.SetAudioAsAutoplay(audioShape); } } catch (COMException) { // Adding the file failed for one reason or another - probably cancelled by the user. } } } return(audioFiles); }
public static void AddDrillDownAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide, out PowerPointDrillDownSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true) { try { if (currentSlide == null || currentSlide.Index == PowerPointPresentation.Current.SlideCount) { System.Windows.Forms.MessageBox.Show("No next slide is found. Please select the correct slide", "Unable to Add Animations"); addedSlide = null; return; } //Pick up the border and shadow style, to be applied to zoomed shape selectedShape.PickUp(); PrepareZoomShape(currentSlide, ref selectedShape); PowerPointSlide nextSlide = GetNextSlide(currentSlide, deletePreviouslyAdded); PowerPoint.Shape nextSlidePicture = null, shapeToZoom = null; currentSlide.HideIndicator(); if (backgroundZoomChecked) { nextSlidePicture = GetNextSlidePictureWithBackground(currentSlide, nextSlide); nextSlidePicture.Apply(); PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture); addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide(); addedSlide.DeleteAllShapes(); nextSlidePicture.Copy(); shapeToZoom = addedSlide.Shapes.Paste()[1]; addedSlide.DeleteShapeAnimations(shapeToZoom); currentSlide.Copy(); var backgroundShape = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; backgroundShape.Apply(); Utils.Graphics.FitShapeToSlide(ref backgroundShape); backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward); backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); addedSlide.PrepareForDrillDown(); addedSlide.AddDrillDownAnimationBackground(backgroundShape, shapeToZoom, nextSlidePicture); } else { PowerPoint.Shape pictureOnNextSlide = null; nextSlidePicture = GetNextSlidePictureWithoutBackground(currentSlide, nextSlide, out pictureOnNextSlide); nextSlidePicture.Apply(); PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture); addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide(); addedSlide.DeleteAllShapes(); nextSlidePicture.Copy(); shapeToZoom = addedSlide.Shapes.Paste()[1]; addedSlide.DeleteShapeAnimations(shapeToZoom); currentSlide.Copy(); var backgroundShape = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; backgroundShape.Apply(); Utils.Graphics.FitShapeToSlide(ref backgroundShape); backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward); backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); addedSlide.PrepareForDrillDown(); addedSlide.AddDrillDownAnimationNoBackground(backgroundShape, shapeToZoom, pictureOnNextSlide); pictureOnNextSlide.Delete(); } currentSlide.ShowIndicator(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index); Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview"); if (includeAckSlide) { PowerPointPresentation.Current.AddAckSlide(); } } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "AddDrillDownAnimation"); ErrorDialogWrapper.ShowDialog("Error when adding drill down animation", "An error occurred when adding drill down animation.", e); throw; } }