Shape and text animations

Hi, Aspose. I have a shape with different kind of animations, the first one is a shape animation and the rest is text animations. Is there a way to get and remove this first animation? I’ve checked all the properties inside all the animation objects, but still can’t discriminate shape animation of text animations. I prepared a sample project to make things clearer:
https://drive.google.com/file/d/1Te5rGUG76DzV1tUW_UaIzSGHo3PgFLXM/view?usp=sharing
I need to find and remove this Rectangle4 animationimage.png (10.7 KB)

@obrusentsov

The animations sequences are added in order of their appearance on slide in main sequence collection. You can try using following code to delete the required one.

        using (Presentation pres = new Presentation("aspose sample.pptx"))
        {
            var shape = pres.Slides[0].Shapes[0];
            //there is 9 animations. One of them is a shape animation, and the other ones are text animations. 
            //I need to get the shape animation
            var animations = pres.Slides[0].Timeline.MainSequence.GetEffectsByShape(shape);

            pres.Slides[0].Timeline.MainSequence.RemoveAt(0);
            pres.Save("saved.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
        }

I’m not sure that animated shape will always be the first one, i need to be sure.

@obrusentsov

Actually, when you try to get shape effects, it will return you all effects applied on that shape. You can try using following approach to serve the purpose.

    static void Main(string[] args)
    {
        using (Presentation pres = new Presentation("aspose sample.pptx"))
        {
            var shape = pres.Slides[0].Shapes[0];
            //there is 9 animations. One of them is a shape animation, and the other ones are text animations. 
            //I need to get the shape animation
            List<IEffect> animeffects = new List<IEffect>();

            var animations = pres.Slides[0].Timeline.MainSequence.GetEffectsByShape(shape);
            
            animeffects.AddRange(pres.Slides[0].Timeline.MainSequence.GetEffectsByParagraph(((IAutoShape)shape).TextFrame.Paragraphs[0]));
            animeffects.AddRange(pres.Slides[0].Timeline.MainSequence.GetEffectsByParagraph(((IAutoShape)shape).TextFrame.Paragraphs[1]));
            animeffects.AddRange(pres.Slides[0].Timeline.MainSequence.GetEffectsByParagraph(((IAutoShape)shape).TextFrame.Paragraphs[2]));
            animeffects.AddRange(pres.Slides[0].Timeline.MainSequence.GetEffectsByParagraph(((IAutoShape)shape).TextFrame.Paragraphs[3]));
            animeffects.AddRange(pres.Slides[0].Timeline.MainSequence.GetEffectsByParagraph(((IAutoShape)shape).TextFrame.Paragraphs[4]));
            animeffects.AddRange(pres.Slides[0].Timeline.MainSequence.GetEffectsByParagraph(((IAutoShape)shape).TextFrame.Paragraphs[5]));
            animeffects.AddRange(pres.Slides[0].Timeline.MainSequence.GetEffectsByParagraph(((IAutoShape)shape).TextFrame.Paragraphs[6]));

            var shapeSequence = pres.Slides[0].Timeline.MainSequence.ToList().Except(animeffects).ToArray();


            pres.Slides[0].Timeline.MainSequence.Remove(shapeSequence[0]);
            pres.Save("saved.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
        }

Thank you, will try this approach right away

@obrusentsov

I hope this shall work on your end.

It doesn’t work, the result is barely predictible. Is there a way to clone a shape with animation?

In Powerpoint there is a check mark “Animate attached shape” image.png (3.9 KB)
is there a way to work with it through Aspose API?

@obrusentsov

We need to investigate this further on our end and will get back to you with feedback as soon as possible.

i think i found checkbox needed, it’s inside effect.TextAnimation.EffectAnimateBackgroundShape property

@obrusentsov

Yes, the shape cloning clones the animation effects too. Please use following snippet:

using (Presentation pres = new Presentation("aspose sample.pptx"))
{
    ISlide slide = pres.Slides[0];
    IShapeCollection shapes = slide.Shapes; 
    IAutoShape shape = (IAutoShape)slide.Shapes[0];
    
    shapes.AddClone(shape, 10, 10);
    
    pres.Save("saved-cloned.pptx", SaveFormat.Pptx);
}