-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shape: set z-order of shape in slide #49
Comments
@scanny Any pointers as to where to look in the code for something like this ? |
The z-order of shapes on a slide is determined solely by their document order in the slide part (e.g. slide1.xml). So the general gist would be to re-order that sequence of elements. The shapes in a slide are contained in the slide's "shape tree", a If you see how far you can get with that, feel free to ask more questions about the finer points, as needed :) |
Thanks @scanny |
If you can post the operative bit of the code you developed, that would be a help to others who arrive here on search. Glad you got it working :) |
An example with a picture: picture = slide.shapes.add_picture(
image, Cm(left), Cm(top), height=Cm(height)
)
# move picture to background
slide.shapes._spTree.remove(picture._element)
slide.shapes._spTree.insert(2, picture._element) # use the number that does the appropriate job |
Awesome, thanks @NotSqrt :) |
+1 for this feature request. I tried the example above but it seems to create a slide that crashes powerpoint when opened. |
when I try to do this : shape = shapes.add_shape(MSO_SHAPE.RECTANGLE,left,top,width,height)
slide.shapes._spTree.remove(shape._element) an error says: shape object has no attribute ’_Element' did I make a mistake here? |
Looks like a typo. All shapes have the attribute |
It is not a typo actually, I typed shape._element or shape._Element , Error always says:
Not a typo |
What is the type of the object you get back? shape = shapes.add_shape(MSO_SHAPE.RECTANGLE, left, top, width, height)
print(shape.__class__) # or perhaps print(shape.__class__.__name__) And what available attributes to you find when you introspect into print(dir(shape)) |
Is there a workaround other than using _spTree.remove and _spTree.insert? It creates corrupted pptx files which generate an alert when opening in MS Powerpoint. Thanks |
I don't believe you have to actually remove and insert to change the order. Perhaps counterintuitive to the naming, I believe the So you could do something like this to move a shape from ninth position to fourth: # shape will be positioned relative to this one, hence the name "cursor"
cursor_sp = shapes[3]._element
cursor_sp.addprevious(shapes[8]._element) |
thanks @scanny! I used the following to move a picture I added using add_picture to the background:
MS Powerpoint opens the file without complaining |
@chrismcmc Glad to hear you got it working :) |
No description provided.
The text was updated successfully, but these errors were encountered: