Wednesday 13 June 2018

python - ArcObjects + comtypes at 10.1 and newer


Has anyone played around with using ArcObjects in Python at version 10.1?


I am having all sorts of problems, such as TypeErrors when wrapping the ESRI OLB modules and AttributeErrors when attempting to use a method or property of a wrapped module.


Anyone had any better luck?



Answer



As of July 2015 release 1.1.2 comtypes has the patch from below applied. :) Install using pip from PyPi or from github:



pip install comtypes

pip install https://github.com/enthought/comtypes/archive/master.zip



There is a fix for this, taken from the ArcGIS Forums: 10.1 beta and comtypes. Edit comtypes module, under PYTHONPATH\lib\site-packages and add the following entry to the _ctype_to_vartype dictionary in automation.py:



POINTER(BSTR): VT_BYREF|VT_BSTR,

You may also need to delete automation.pyc, automation.pyo, safearray.pyc, and safearray.pyo in the same folder.



Also see page 5 of Mark Cederholm's 2012 Dev Summit presentation: ArcMap and Python: Closing the VBA Gap, and in the header of his updated snippets modules for 10.0, 10.1 and 10.2 respectively; index page: http://pierssen.com/arcgis10/python.htm




There is a pull request to merge the patch into master comtypes; still open because Enthought (rightly) won't apply patches without accompanying tests.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...