comtypes

Python win32com.client.Dispatch looping through Word documents and export to PDF; fails when next loop occurs

你。 提交于 2019-12-03 09:43:08
Based on the script here: .doc to pdf using python I've got a semi-working script to export .docx files to pdf from C:\Export_to_pdf into a new folder. The problem is that it gets through the first couple of documents and then fails with: (-2147352567, 'Exception occurred.', (0, u'Microsoft Word', u'Command failed', u'wdmain11.chm', 36966, -2146824090), None) This, apparently is an unhelpful general error message. If I debug slowly it using pdb, I can loop through all files and export successfully. If I also keep an eye on the processes in Windows Task Manager I can see that WINWORD starts

Retrieve output parameters from an AutoCAD API method in python

只愿长相守 提交于 2019-12-02 13:33:12
I'm trying to retrieve 2 output Arrays from an XRecord in AutoCAD 2016 using python 2.7, with comtypes imported, the first array is an array of integers (DXF Group Codes) and the second array is an array of variants (the values of XRecord). The opposite way of what this question seeks to The method of interest is GetXRecordData , which (according to AutoCAD's documentation) if successful returns None , and only accepts 2 output arguments . when I try to retrieve it with code like DxfGrCd = [] vals = [] an_XRecord.GetXRecordData(DxfGrCd, vals) and see the values of DxfGrCd and vals I found no

How to pass POINT structure to ElementFromPoint method in Python?

微笑、不失礼 提交于 2019-11-28 10:40:58
问题 I'm trying to use method IUIAutomation::ElementFromPoint in Python using comtypes package. There are many examples how to use it in C++, but not in Python. This simple code reproduces the problem on 64-bit Windows 10 (Python 2.7 32-bit): import comtypes.client UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll') UIA_dll.IUIAutomation().ElementFromPoint(10, 10) I get the following error: TypeError: Expected a COM this pointer as first argument Creating the POINT structure this way doesn