I found a solution posted on the ArcGIS forums. It simply involves modifying automation.py
in the comtypes source. Add the entry POINTER(BSTR): VT_BYREF|VT_BSTR
to the _ctype_to_vartype
dictionary.
After this, all the .olb's load.
Pergunta
I'm trying to access the .olb files that ship with ArcGIS10.1 using the comtypes module. Some of the .olb files work (esriGeometry.olb) and some of them don't (esriSystem.olb), and some of them work some of the time (esriSearch.olb).
The following code
from comtypes.client import GetModule
olb_path = 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\com\\esriSystem.olb'
m = GetModule(path)
raises this traceback and exception
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
test3()
File "D:\Data\MatthewPlourde\JAMES\gis_tools\tool.py", line 139, in test3
m = GetModule(path)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\client\_generate.py", line 112, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\client\_generate.py", line 188, in _CreateWrapper
mod = _my_import(fullname)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\client\_generate.py", line 26, in _my_import
return __import__(fullname, globals(), locals(), ['DUMMY'])
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\gen\_5E1F7BC3_67C5_4AEE_8EC6_C4B73AAC42ED_0_10_1.py", line 5705, in <module>
( ['in'], POINTER(_midlSAFEARRAY(POINTER(BSTR))), 'pParameters' ),
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\safearray.py", line 18, in _midlSAFEARRAY
sa_type = _make_safearray_type(itemtype)
File "C:\Python27\ArcGIS10.1\lib\site-packages\comtypes\safearray.py", line 53, in _make_safearray_type
raise TypeError(itemtype)
TypeError: <class 'comtypes.errorinfo.LP_BSTR'>
Apparently comtypes.safearray._make_safearray_type
doesn't know what to do with <class 'comtypes.errorinfo.LP_BSTR'>
. If there's anyone out there using ArcGIS10.1, I'd be grateful to know whether you can reproduce this error, and especially grateful if you know the cause.
Solução
I found a solution posted on the ArcGIS forums. It simply involves modifying automation.py
in the comtypes source. Add the entry POINTER(BSTR): VT_BYREF|VT_BSTR
to the _ctype_to_vartype
dictionary.
After this, all the .olb's load.
Outras dicas
I too, am having this exact error and I can't get past it. If you find out what happens please update this. The only thing I can find is something saying that there may be mixing 32 bit with 64 bit libs. (also, I don't see where I can send a reply to your question... only an answer. I don't use stackexchange much)
Let me add something that may help you, this was taken from: http://forums.arcgis.com/threads/15848-ArcMap-10-ArcObjects-and-Python-very-cool-but-help-with-a-couple-of-problems
import logging
# grab rootlogger
_loggy = logging.getLogger()
_loggy.setLevel(logging.DEBUG)
_loggy.addHandler(logging.FileHandler("derpdebug.log"))
import os
import comtypes.client
# change com_dir to whatever it is for you
com_dir = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\com'
coms = [os.path.join(com_dir, x) for x in os.listdir(com_dir) if os.path.splitext(x)[1].upper() == '.OLB']
map(comtypes.client.GetModule, coms)
# check add whatever you want here.
import comtypes.gen.esriArcMapUI
import comtypes.gen.esriGeodatabase
print dir(comtypes.gen.esriArcMapUI)
Then I just did: grep -v ^Release derpdebug.log >readable.log