Albert Strasheim wrote:
> Hello all
>
> I'm new to the world of COM automation with Python, so please bear with me.
>
> I'm trying to automate Golden Software's Surfer 8 [1] using Python.
>
> The basics seems to be working fine, but I'm running into a problem when 
> dealing with a collection containing instances of an object derived from a 
> base object.
>
> The code looks as follows. Judging from the VBScript examples included with 
> Surfer
Which VBScript examples? The one I looked at (CONTOURFILL.BAS) uses 
Overlays to access Levels:

Set MapFrame = Doc.Shapes.AddContourMap(GridFileName:=Path+"demogrid.grd")
'Fill Contours
MapFrame.Overlays(1).FillContours = True
'Set the colors to be gradational from green to blue
Set Levels = MapFrame.Overlays(1).Levels



> , it should work.
>
> from win32com.client import constants, Dispatch
> srf = Dispatch("Surfer.Application")
> plot = srf.Documents.Add(constants.srfDocPlot)
> mapframe = plot.Shapes.AddContourMap(GridFileName=outGrid)
> contourmap = mapframe .Overlays.Item(1)
> # the next line breaks
> print contourMap.Levels
>
> contourmap should contain a Surfer.IContourMap object, which is derived from 
> the Surfer.IShape object. I can see in the GUI that the contour map is 
> created, so I'm pretty sure everything is working up to this point.
>
> Now, IContourMap has a Levels property that IShape doesn't have. When I try 
> to access this property, I get the following exception:
>
> Traceback (most recent call last):
>   File "surfer.py", line 7, in <module>
>     print contourMap.Levels
>   File "C:\Python25\Lib\site-packages\win32com\client\__init__.py", line 
> 454, in __getattr__
>     raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), 
> attr)
> AttributeError: '<win32com.gen_py.Surfer 8 Type Library.IShape instance at 
> 0x22544016>' object has no attribute 'Levels'
>
> For some reason Python can't figure out that the IShape is also a 
> IContourMap.
>
> As I said, I'm new to COM, so I'm at a loss as to what's going on here? Any 
> help would be appreciated.
>
> Cheers,
>
> Albert
>
> [1] http://www.goldensoftware.com/products/surfer/surfer.shtml 
>
> _______________________________________________
> 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