[python-win32] COM Automation: Problem Accessing Property of Object

Emre CETIN e.cetin at yahoo.com
Tue May 22 04:31:13 EDT 2018


Hi, I've been looking for a solution to this question for some time now. Hopefully you could help me out. There's a program (Golden Software Surfer) that I have successfully automated using Python COM. I normally am able to control every portion I need. The part I have trouble accessing is under its "Property Manager". Even though I am using the description provided in the software's documents & help files I get an error saying:
AttributeError: '<win32com.gen_py.Surfer 13 Type Library.IShape instance at 0x2327715907232>' object has no attribute 'ShowColorScale'
"ShowColorScale" is just an example of one property/method in the Property Manager window.
Here is the example code I have been working with:
import win32com.client

srf = win32com.client.gencache.EnsureDispatch('Surfer.Application')
Plot = srf.Documents.Add(1)
srf.Visible = True
MapFrame1 = Plot.Shapes.AddImageMap(GridFileName="C:/test.grd")
ImageLayer1 = MapFrame1.Overlays(1)
ImageLayer1.ShowColorScale = True  # this is where i get the error
The full error message:KeyError                                  Traceback (most recent call last)
C:\Program Files\Anaconda3\lib\site-packages\win32com\client\__init__.py in __setattr__(self, attr, value)
    470                 try:
--> 471                         args, defArgs=self._prop_map_put_[attr]
    472                 except KeyError:

KeyError: 'ShowColorScale'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-7-8ef841af10d0> in <module>()
----> 1 ImageLayer1.ShowColorScale = True # test

C:\Program Files\Anaconda3\lib\site-packages\win32com\client\__init__.py in __setattr__(self, attr, value)
    471                         args, defArgs=self._prop_map_put_[attr]
    472                 except KeyError:
--> 473                         raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
    474                 self._oleobj_.Invoke(*(args + (value,) + defArgs))
    475         def _get_good_single_object_(self, obj, obUserName=None, resultCLSID=None):

AttributeError: '<win32com.gen_py.Surfer 13 Type Library.IShape instance at 0x2327715907232>' object has no attribute 'ShowColorScale'

After searching on the net I found this question, asked here 10 years ago:[python-win32] COM automation: problem accessing property of derived object obtained from collection « python-win32 « ActiveState List Archives

| 
| 
| 
|  |  |

 |

 |
| 
|  | 
[python-win32] COM automation: problem accessing property of derived obj...


 |

 |

 |



It's almost identical to my issue. The author mentions that he found a solution on his latest post too. But doesn't post the solution itself. Just something regarding CastTo and then gives two links for reference. (Tried to search and understand CastTo without any success, couldn't understand how to implement it to the code above.)

I'm new to programming & Python.. especially to COM. I would really appreciate it if some one could help me solve this.

[Python3.6, Surfer13]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20180522/160308ec/attachment.html>


More information about the python-win32 mailing list