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

2 Answers 2

up vote 5 down vote accepted
+50

Aha -- there is a fix for this on the ArcGIS Forums: 10.1 beta and comtypes. The fix is applied to the comtypes module, under PYTHONPATH\lib\site-packages, not Snippets.

I noticed that the current version of comtypes croaks when trying to wrap esriSystem.olb. Fortunately, you can remedy this by adding the following entry to the _ctype_to_vartype dictionary in automation.py:

POINTER(BSTR): VT_BYREF|VT_BSTR,

After making that little tweak it works fine (so far). 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

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

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.