-
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
feature set: SmartArt support #83
Comments
Thanks for this Nick. Definitely looks like a serious job to get right. This will be a handy start when the time comes. Let me know if you decide to dig into it later, happy to help you find internal bits that might be useful for injecting templated XML or what have you :) |
Is there a bit of sample code that would demonstrate changing the XML of |
Hi Piper, I don't have time to test something at the moment, but this should point you in the right direction. Essentially you can read part.blob and write part._element. The former is XML text (probably unicode), the latter is an lxml.objectify tree. In general you don't have to trace back up to the part from a shape, the slide object itself is the part. So accessing the XML would be: slide = prs.slides[0]
xml = slide.blob If you prefer to work directly with the objectify tree (like ElementTree, but can access children mostly with attribute access), you can use once you're done, you'll need to put it back in element form. If you've directly manipulated the element tree using the from pptx.oxml import parse_xml_bytes
element = parse_xml_bytes(your_xml)
slide._element = element Never mind the From there you should be able to save normally. Theoretically you should be able to do additional operations on the slide, but I'll bet I'm cacheing some references somewhere, so accessing shapes after reparsing the XML might not work. That might be something worth looking into if the use case is compelling. That and providing built-in hooks for accessing the XML directly. Let me know how you go :) |
I had a look into what it might take to be able to use placeholders that are within SmartArt elements (as a workaround which may be easier than full support for inserting new SmartArt), but it seems like some extra plumbing is needed - the placeholders are in related parts, and have a different representation (
<dgm:prSet phldrT="[Text]" phldr="1"/>
vs. the normalp:nvPr/p:ph
)The general approach seems to be a graphicFrame which contains a graphicData:
The relationships provide the layout of the shape, and the actual content:
The placeholders then look like this (from data1.xml):
I saw that I can find the related part's XML with
shape.part.related_parts['rId2']
. Possibly I can manipulate that directly.This is the output of
print prs.slides[0].shapes[0].part.blob
:To have something which can generate SmartArt, I thought of putting the SmartArt items I'd like to use into the slide layouts - and then populating the placeholders. This would be a temporary measure until an
add_smartart()
is created.Unfortunately for now, it looks like this will take longer than I have to implement, but I wanted to at least create an issue to track and say what I know so far.
The text was updated successfully, but these errors were encountered: