Thanks very much for the reply -- that got me a good way there, but  
now I have further questions.

I'm working with some ESRI com libraries. I've managed to retrieve an  
ILayer from an IMap and then cast IFeatureLayer from the ILayer.

fc = layer.QueryInterface(comtypes.gen.esriGeoDatabase.IFeatureLayer)

I don't have much experience at all with COM and what's confusing me  
now is difference between methods and properties as they are seen by  
comtypes. I can do

feature.DataSourceType

and get:

u'Personal Geodatabase Feature Class'

but doing:

feature.FeatureClass

which is what I really need to do, yields:

<bound method POINTER(IFeatureLayer).FeatureClass of <POINTER 
(IFeatureLayer) object cbc990>>

And

feature.FeatureClass()

yields:

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: required argument 'fclass' missing

fclass needs to be a pointer to an IFeatureClass whose CoClass,  
FeatureClass, is a non-creatable COM class.

I'm not sure if matters but the relevant parts of feature._methods_ are:

(<class 'ctypes.HRESULT'>, '_get_FeatureClass', (<class  
'ctypes.LP_POINTER(IFeatureClass)'>,), ((10, 'fclass'),), ('propget',  
u"The layer's feature class."), u" The layer's feature class.")

(<class 'ctypes.HRESULT'>, 'FeatureClass', (<class 'comtypes.POINTER 
(IFeatureClass)'>,), ((1, 'fclass'),), ('propputref', u"The layer's  
feature class."), u"The layer's feature class.")

(<class 'ctypes.HRESULT'>, '_get_DataSourceType', (<class  
'ctypes.LP_BSTR'>,), ((10, 'Text'),), ('propget', u'Data source  
type.'), u'Data source type.')

(<class 'ctypes.HRESULT'>, '_set_DataSourceType', (<class  
'comtypes.BSTR'>,), ((1, 'Text'),), ('propput', u'Data source  
type.'), u'Data source type.')

Lastly, feature.FeatureClass works fine in VB, for what that's worth.

FeatureClass is read-only. Would that have anything to do with it?

thanks very much,

Nick

On Oct 18, 2007, at 8:25 PM, Andrew MacIntyre wrote:

> Nick Collier wrote:
>
>> I'm trying to use python to work with the various ESRI (the GIS
>> folks) com libraries. However, I'm running into some difficulties.
>>
>>   I've run makepy on the type library I'm interested in working with
>> and that yields:
>>
>> ...
>> # This CoClass is known by the name 'esriSystem.AoInitialize.1'
>> class AoInitialize(CoClassBaseClass): # A CoClass ...
>>
>>
>> But dispatching to that
>>
>>>>> client.Dispatch("esriSystem.AoInitialize.1")
>> Traceback (most recent call last):
>>    File "<interactive input>", line 1, in <module>
>>    File "C:\Python25\Lib\site-packages\win32com\client\__init__.py",
>> line 95, in Dispatch
>>      dispatch, userName = dynamic._GetGoodDispatchAndUserName
>> (dispatch,userName,clsctx)
>>    File "C:\Python25\lib\site-packages\win32com\client\dynamic.py",
>> line 98, in _GetGoodDispatchAndUserName
>>      return (_GetGoodDispatch(IDispatch, clsctx), userName)
>>    File "C:\Python25\lib\site-packages\win32com\client\dynamic.py",
>> line 78, in _GetGoodDispatch
>>      IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
>> pythoncom.IID_IDispatch)
>> com_error: (-2147467262, 'No such interface supported', None, None)
>>
>> I'm assuming that this is because this doesn't implement IDispatch.
>>
>> The relevant VB code does:
>>
>> Set m_pAoInitialize = New AoInitialize
>>
>> Is there any equivalent in win32com (or even ctypes) that I can  
>> use to
>
>> get this working or is Python out of the question here?
>
> A lot of the ESRI COM stuff doesn't support IDispatch.  ctypes,  
> with the
> comtypes add-on module, can be used to call the ESRI COM interfaces
> quite successfully in my experience.
>
> I've not tried using the ESRI 9.x stuff yet - still using 8.3 and an
> ancient version of ctypes.  With the ESRI 8.x TLBs, there were issues
> where many of the names were declared out of order as far as Python  
> was
> concerned and the generated modules had to be manually edited to  
> rectify
> this.  With 9.x, ESRI split the TLBs up a lot more so I don't know how
> much this affects what gets generated.
>
> -------------------------> "These thoughts are mine alone!" <---------
> Andrew MacIntyre           National Licensing and Allocations Branch
> tel:   +61 2 6219 5356     Inputs to Industry Division
> fax:   +61 2 6253 3277     Australian Communications & Media Authority
> email: [EMAIL PROTECTED]
> _______________________________________________
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to