We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to get all shapes from a slide inherited from master, layout?

Hi,
I am trying to access all the shapes from a single slide. But some shapes are only present in layout slide. How can i access the final(that we see in powerpoint ) slide shapes inherited from all masters, layouts?.
Lets say i have a title box shape saying “click here to add title” in layout slide, which is being used by a slide title box with different text “Slide Title” using the layout’s format. When i get shapes from layoutSlide and RegularSlide, I get two different shapes where i am only interested in “Slide Title” of RegularSlide with formatting applied from layout slide

@pravin254,l

I have observed your requirements and suggest you to please visit the following thread link for your kind reference.

The above code only compares placeholder type,size,orientation. It does not work if I have two shapes of same placeholder type,size and orientation in the layout slide. Moreover, I have another question.
how can i differentiate which shapes in layout slide are visible in the dependant slides.
Thanks

@pravin254,

Actually, the sample code that I have shared is checking all shapes based on PlaceholderType. The shapes from Master or Layout have PlaceholderType not null. Otherwise, for normal slide shapes added the placeholder type is null. For your second question related to which shapes from layout slide are visible on dependent slide, I like to add here that all shapes from LayoutSlide are visible on dependent slides when ever a layout slides is applied to any normal slide.

Hi @mudassir.fayyaz,
Thanks for the fast reply!
I have attached a test pptx file that addresses both the issues.
The file has 5 shapes in layout slide and 2 shape in regular/dependant slide.
Question 1:
while searching for layout slide shapes from the single shape in regular slide, it matches with two shapes in layout slide. Temp fix: Also, comaparing placeholder index solves my problem in this case.
Question 2:
When I combine 5 shapes from layout and 2 shape in dependant slide. I get 7 shapes, when ignoring inherited shape from layout slide, I get 5 shapes in total. But only one shape is visible in regular slide
Please find the attached pptx file in ziptest.zip (21.0 KB)

@pravin254,

I have tried accessing the presentation shapes in your presentation. The slide is returning 2 shapes. Can you please confirm if Q1 of yours is some issue or a feedback.

I am unable to reproduce your Q2. Can you please provide the presentation and working sample code reproducing your requirements so that I may help you.

        public static List<IShape> TestMasterShape(Presentation pres,IShape shape,ILayoutSlide lSlide)
    {
            var matchingShapes = new List<IShape>();
            if (shape.Placeholder != null)
            {
                //It means shape is inherited from master

                PlaceholderType type = shape.Placeholder.Type;

                //Checking layout slide
                foreach (IShape lShape in lSlide.Shapes)
                {
                    if (lShape.Placeholder.Type == shape.Placeholder.Type &&
                        lShape.Placeholder.Size == shape.Placeholder.Size &&
                        lShape.Placeholder.Orientation == shape.Placeholder.Orientation)
                    {
                        String s = "matching shape found";
                        matchingShapes.Add(lShape);
                    }

                }
            
            }
    
        return matchingShapes;
    }
    static void Main(string[] args)
    {
        if (checkLicense())
        {
            Console.WriteLine("Aspose license found");
        }
        else
        {
            Console.WriteLine("Aspose license not found");
        }
        string fileName = "t.pptx";
        Presentation pres = new Presentation(fileName);
        //Question 1: Find the inherited shapes from layout shapes for slide[0].shapes[0];
        var firstSlideFirstShape = pres.Slides[0].Shapes[0];
        var matchingLayoutShapes = TestMasterShape(pres,firstSlideFirstShape,pres.Slides[0].LayoutSlide);
        Console.WriteLine("Matching master shapes " + matchingLayoutShapes.Count.ToString());
        //Here the matching layout slide's shapes for first slide's first shape are 2.
        //But actually, the slide[0].shape[0] only inherits from single shape from layoutSlide

        //Question 2: How to determine shapes only displayed in slide.
        //You have said that all layoutSlide's shape combined with regular slides shapes will
        //represent the final slide's shapes.But 

        Console.WriteLine("Slide Shapes Count "+pres.Slides[0].Shapes.Count.ToString());
        Console.WriteLine("Layout Shapes Count "+pres.Slides[0].LayoutSlide.Shapes.Count.ToString());
        Console.WriteLine("Master Shapes Count "+pres.Slides[0].LayoutSlide.MasterSlide.Shapes.Count.ToString());
       
       //Here the layout slides shape count is 5, 
       //slide shapes count is 2,
       //master slide's shape count is 5,
       //How do i get the final shapes? 
    }
}

Find the attached zip file that contains t.pptx t.zip (21.0 KB)

@pravin254,

I have worked with the sample code shared and suggest you to please try using following modified sample code on your end to address Q1.

			foreach (IShape lShape in lSlide.Shapes)
			{
				if (lShape.Placeholder.Type == shape.Placeholder.Type &&
					lShape.Placeholder.Size == shape.Placeholder.Size &&
					lShape.Placeholder.Orientation == shape.Placeholder.Orientation)
				{
					if (lShape.X == shape.X && lShape.Y == shape.Y)
					{
						String s = "matching shape found";
						matchingShapes.Add(lShape);
					}
				}

			}

Now, coming to Q2 regarding layout shapes availability of normal slides. I like to share that when you add a new slide by selecting a particular layout slide, the shapes on layout slides will get appear on added slide. The Master slides available on LayoutSlide will be available on normal slide by stetting following property explicitly.

		pres.Slides[0].ShowMasterShapes = true;

When you apply a layout slide, it copies the shapes on layout slide on normal slide. They are not sort of linked shapes that get inherits from Layout slide to normal but a copy of that. So, you have provision to manage and remove the shapes that have come from LayoutSlide when Layout slide was applied. You can get the difference the same way as you have used in your code that which of slides from Layout are available on normal slides and which are not.

@mudassir.fayyaz Thanks again,

The fix for Q1 works.
But, for Q2 even if i set pres.Slides[0].ShowMasterShapes = true;. I get only two shapes in slide[0] for the above pptx file.

you have provision to manage and remove the shapes that have come from LayoutSlide when Layout slide was applied

I dont understand this statement clearly. What do you mean by applying layout slide?
Can you share code example?
Thanks

@pravin254.

I suggest you to please try using following sample code to understand the concept. When you add the new slide even with LayoutSlide of first slide, you can observe that it will copy the shapes from used layout slide to newly added slide.

		Presentation pres = new Presentation(fileName+ "t.pptx");
		//Question 1: Find the inherited shapes from layout shapes for slide[0].shapes[0];
		var firstSlideFirstShape = pres.Slides[0].Shapes[0];

		ISlide newSlides=pres.Slides.AddEmptySlide(pres.Slides[0].LayoutSlide);
		//The following call when set true will show a shape that is added on Master slide
		//Generally people add logo shape on master slide that they expect to be available on all slides
		newSlides.ShowMasterShapes = true;
		pres.Save(fileName + "Saved.pptx", SaveFormat.Pptx); 

Secondly for master slide shapes. When you add any shape on Master slide and when you will use the following statement to true, the shape from master slide will appear on added slide.

pres.Slides[0].ShowMasterShapes = true;

@mudassir.fayyaz ,
Thanks. I understood how it works.

@pravin254,

You are always welcome.