Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
I removed the 10.1 version specific tag because this same error and fix applies to 10.1, 10.2, and 10.3 (and we don't have a 10.x tag). Also it doesn't need arcgis tag as there aren't any arcobjects without it. –  matt wilkie May 13 at 21:40

2 Answers 2

up vote 8 down vote accepted
+50

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.

share|improve this answer
    
+1 Unfortunately, this doesn't fix everything, though. calling comtypes.client.GetModule on esriDataSourcesOleDB.olb, esriGlobeCoreUI.olb, and esriSchematicControls.olb still generates attribute errors. Furthermore, the coclasses that should be accessible in esriFramework.olb (such as AppROT), aren't. –  Matthew Plourde Jul 16 '13 at 19:00
    
Anyone tried this fix for 10.2 with results? –  Conor May 7 '14 at 15:19
1  
Works fine for me with the above fix. –  blah238 May 7 '14 at 15:22
    
Fix above worked for me in 10.2, Thanks @blah238 –  dklassen Jul 7 '14 at 22:46
1  
I submitted a pull request to the comtypes project on GitHub: github.com/enthought/comtypes/pull/75. If this fix is applied upstream we won't need to do this anymore. –  matt wilkie Jan 15 at 20:34

To gain access to arcobjects (10.1) via python I had to delete automation.pyc, automation.pyo, safearray.pyc and safearray.pyo in the comtypes directory. I also deleted all of the files in the C:\Users\USER_ID\AppData\Roaming\Python\Python27\comtypes_cache and had to change the

ProductList = [esriSystem.esriLicenseProductCodeArcInfo, esriSystem.esriLicenseProductCodeArcEditor, esriSystem.esriLicenseProductCodeArcView]

to [esriSystem.esriLicenseProductCodeAdvanced, esriSystem.esriLicenseProductCodeStandard, esriSystem.esriLicenseProductCodeBasic].

The last thing that I did was search the syntax for all “10.0” strings and replaced them with “10.1”.

share|improve this answer
    
An alternative to deleting the cache manually is to (re)create the cache with comtypes.client.GetModule( 'filename.olb' ). See github.com/maphew/arcplus/blob/master/arcplus/ao/test.py (worked for me, may not elsewhere). –  matt wilkie Jul 14 at 20:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.