comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

How do I access enumerations?

Open OskarPersson opened this issue 7 years ago • 3 comments
trafficstars

How do I access enumerations and their values such as powerpoint.ppsaveasfiletype through comtypes?

OskarPersson avatar Sep 13 '18 11:09 OskarPersson

I answered your Stack Overflow question, but let’s record it here too:

Use the comtypes.client.Constants() class to access all associated enum names, including those defined on the ppSaveAsFileType enum:

from comtypes.client import Constants, CreateObject

powerpoint = CreateObject("Powerpoint.Application")
pp_constants = Constants(powerpoint)

pres = powerpoint.Presentations.Open(input_path)
pres.SaveAs(output_path, pp_constants.ppSaveAsPDF)

Maintainers: why is the Constants() class not documented?

mjpieters avatar Sep 13 '18 20:09 mjpieters

TIL there is a Constants class. (That's my excuse.)

cfarrow avatar Sep 13 '18 20:09 cfarrow

😆 Added in December 2008 https://github.com/enthought/comtypes/blob/1d3d38b2a616674309e7eabe6b5c581042caf32a/CHANGES.txt#L320-L330

mjpieters avatar Sep 13 '18 20:09 mjpieters

@OskarPersson @mjpieters @cfarrow

If the issue remains, please re-open.

junkmd avatar Dec 03 '22 07:12 junkmd