Open CrunchCube opened 4 years ago
I'd like to add my support for this feature request! I won't be able to transition from VBA until we have support for this feature.
Hi, I'm doing some additional development work on my PPT automation using custom properties and this issue about reading tags (custom properties) in python-pptx came up again. Is it possible to either write/read or just read these tags using python-pptx?
What does the XML look like?
Hi where do I need to look for the required xml? I can see a folder called tags in the zip file which seems to have a number of xml files in there.
Been digging around the XML and Objects. A custom tag added through the vba code are added as:
_
</p:custDataLst>_ in the /ppt/slides/slideX.xml
Looking at PPTX using Open XML SDK for a specific slide I can see a /ppt/tags/tagX.xml for each object that has a custom tag.
slide10.xml.rels in the _rles folder
?xml version="1.0" encoding="UTF-8" standalone="yes"?> Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> Relationship Id="rId8" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags" Target="../tags/tag65.xml"/> Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags" Target="../tags/tag60.xml"/> Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags" Target="../tags/tag64.xml"/> Relationship Id="rId12" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" Target="../charts/chart16.xml"/> Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags" Target="../tags/tag59.xml"/> Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags" Target="../tags/tag58.xml"/> Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags" Target="../tags/tag63.xml"/> Relationship Id="rId11" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" Target="../charts/chart15.xml"/> Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags" Target="../tags/tag62.xml"/> Relationship Id="rId10" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide" Target="../notesSlides/notesSlide6.xml"/> Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags" Target="../tags/tag61.xml"/> Relationship Id="rId9" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout5.xml"/> /Relationships>
here is the xml in a specific tag Source ../tags/tag65.xm ?xml version="1.0" encoding="UTF-8" standalone="yes"?>
I've generated a list of the available tag file for a slide [r.target_partname for r in slide.part.rels if r.reltype == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags' and r.is_external==False]
This generates a list for example ['/ppt/tags/tag1.xml', '/ppt/tags/tag2.xml'].
I would like to iterate over this list and read the file in the list and extract the required data from the xml to create a dictionary
eg
How do I go about reading this path file in python-pptx? Any help will be greatly appreciated!
Hi all, has anyone found a solution to this?
I need to add custom tags to certain shapes. The three-way relationship between the slide's XML file, the relationships XML file, and the specific tag's XML file makes it very tricky to try to manually update the files. Such a simple task with VBA / VST C# but here it looks daunting, has anyone found a workaround?
I haven't found an easy solution, yet. It would probably be easy if I better understood the underlying PPTX file structure. But for now, I'm continuing to use VBA for my PPTX automation scripts. FWIW,Scott On Wednesday, February 21, 2024 at 11:40:08 AM CST, Rodrigo @.***> wrote:
Hi all, has anyone found a solution to this?
I need to add custom tags to certain shapes. The three-way relationship between the slide's XML file, the relationships XML file, and the specific tag's XML file makes it very tricky to try to manually update the files. Such a simple task with VBA / VST C# but here it looks daunting, has anyone found a workaround?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
Witin PowerPoint VBA it is possible to add custom properties for a shape, slide, or presentation. These are set as tags with a key value pair. eg ActivePresentation.Slides(1).Tags.Add "Region", "East"
It is then possible to read (and or update) these custom properties using the tag key eg val = ActivePresentation.Slides(1).Tags("Region") or looping over all the tags to get a specific one
eg
With shape For i = 1 To Tags .Count step 1 If .Name(i) = "PRIORITY" Then do something End If Next End With
I use this feature for ppt automation and configuration. I'm transition over to python and using python-pptx I'm unable to work with these custom tags. Is it possible to add the ability to read these tags (custom properties) for presentations, slide and shapes through the api for example
for tag in shape.tags: if tag.name == 'MOD' do something
or
for tag in shape.tags: if tag('MOD') == 'REFORMAT:
do something