我試圖使用comtypes模塊訪問隨ArcGIS10.1一起提供的.olb文件。一些.olb文件可以工作(esriGeometry.olb),其中一些不會(esriSystem.olb),其中一些工作時間很長(esriSearch.olb)。LP_BSTR上的comtypes內部方法失敗
下面的代碼
from comtypes.client import GetModule
olb_path = 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\com\\esriSystem.olb'
m = GetModule(path)
引發此追蹤和異常
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'>
顯然comtypes.safearray._make_safearray_type
不知道做什麼用<class 'comtypes.errorinfo.LP_BSTR'>
。如果有人使用ArcGIS10.1,那麼我很高興知道您是否可以重現此錯誤,尤其感謝您知道原因。
另請參閱http://gis.stackexchange.com/questions/37672/arcobjects-comtypes-at-10-1 –