HI,
I am facing a problem when parsing a slide. A slide is consist of normal slide and its dependent layout slide and master slide. Some shapes in the normal slide inherit the format from the corresponding shapes in the dependent layout slide and master slide. I want to find out inherit relation, for example shape A in normal slide inherits shape B in its dependent layout slide. Is there any way to find out this relation?
To determine the inheritance relationship of shapes between a normal slide and its dependent layout slide, you can follow these steps:
-
Understanding Shape Inheritance: When a layout slide is applied to a normal slide, the shapes from the layout slide are copied to the normal slide. They are not linked in a way that allows for dynamic inheritance; instead, the shapes are duplicated. This means that while the normal slide may visually appear to inherit properties from the layout slide, they are actually independent copies.
-
Identifying Shapes: You can identify which shapes from the layout slide are present on the normal slide by checking the properties of the shapes. Shapes on the layout slide will have a non-null placeholder type, while shapes on the normal slide will have a null placeholder type.
-
Sample Code: Here’s a sample code snippet that demonstrates how to find shapes on a normal slide that correspond to shapes on a layout slide:
Presentation pres = new Presentation("yourPresentation.pptx"); ISlide normalSlide = pres.Slides[0]; // Access the normal slide IShape firstShape = normalSlide.Shapes[0]; // Access the first shape on the normal slide // Check for matching shapes in the layout slide foreach (IShape layoutShape in normalSlide.LayoutSlide.Shapes) { if (layoutShape.Placeholder.Type == firstShape.Placeholder.Type && layoutShape.Placeholder.Size == firstShape.Placeholder.Size && layoutShape.Placeholder.Orientation == firstShape.Placeholder.Orientation) { if (layoutShape.X == firstShape.X && layoutShape.Y == firstShape.Y) { // A matching shape is found Console.WriteLine("Matching shape found: " + layoutShape.Name); } } }
-
Show Master Shapes: If you want to ensure that shapes from the master slide are also visible on the normal slide, you can set the
ShowMasterShapes
property to true. This will allow you to see shapes that are defined in the master slide.
By following these steps and using the provided code, you should be able to analyze the shapes on your slides and determine their relationships effectively.
Sources:
[1]: How to get all shapes from a slide inherited from master, layout?
Thanks. I use aspose.slide .net via python so I am not sure if the api is right. When I try to get some properties of a shape(e.g. font size or color) in normal slide, I need to use get_effective() to fetch the true value. When I try to get shape_type or AdjustValue’s property like angle_value, I can no longer use this function. Instead I need to find the corresponding shape in layout slide and fetch the property value. Right now I can use shape.placeholder.index to find the corresponding shape. But I am not able to find out inherit relation of the shape without placeholder property in normal slide and layout slide. Is it the only way to compare the position and size of two shape to decide if they are inherited?
@kkk123222,
Unfortunately, we need more details to understand the issue and help you. Could you please share a sample presentation and describe the case?
@kkk123222,
We have opened the following new ticket(s) in our internal issue tracking system and will investigate the case according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESPYNET-226
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thanks. I have done some experiments and comes a conclusion that inheritance only happen in placeholder shapes. If my conclusion is correct, I think I have solved my problem.
A post was split to a new topic: How to Ungroup a GroupShape in a PowerPoint Presentation in Python?
@kkk123222,
Our developers have reviewed your requirements. If a shape is inherited from a placeholder shape on the master or layout slide, you can retrieve the base shape using the get_base_placeholder method. If None is returned, it means the shape is not inherited.
import aspose.slides as slides
with slides.Presentation("presentation.pptx") as pres:
slide = pres.slides[0]
for shape in slide.shapes:
bph = shape.get_base_placeholder()
if type(bph) is slides.AutoShape:
bph.shape_type = slides.ShapeType.CLOUD