[python-win32] COM problems

Tom Adelman tla@research.nj.nec.com
Tue, 24 Apr 2001 15:02:45 -0400


I've included gencache.EnsureModule appropriately and now seem to have
early binding, although my basic problem still presists (i.e. I can't seem
to pass parameters to certain functions).  Now the program looks like (only
the last line here is really important):

import win32com.client
mod =
win32com.client.gencache.EnsureModule('{6E73CA05-CE63-11CF-B59C-0000929132CE
}', 0, 1, 0)
sp = mod.Application()
sp.Visible = 1
nb = sp.Notebooks.Add
nb = mod.Notebook(nb)
sp.ActiveDocument.NotebookItems(2).DataTable.Cell(0,0, 5.2)
gp = sp.ActiveDocument.NotebookItems.Add(mod.constants.CT_GRAPHICPAGE)
gp = mod.GraphItem(gp)
TemplatePage = "Bar Chart for Slide"
x = sp.ActiveDocument.CurrentPageItem.ApplyPageTemplate(TemplatePage)

And running this produces:
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "D:\PythonCode\testSP21.py", line 19, in ?
    x = sp.ActiveDocument.CurrentPageItem.ApplyPageTemplate(TemplatePage)
  File "D:\Program Files\python\win32com\client\dynamic.py", line 429, in
__getattr__
    raise pythoncom.com_error, details
com_error: (-2147352567, 'Exception occurred.', (65535, 'SigmaPlot 6.1',
'No template name supplied.', None, 0, 0), None)

or I can make the last line go through the gencache module:
x = gp.ApplyPageTemplate(vTemplateName=TemplatePage)

to get:
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "D:\PythonCode\testSP21.py", line 17, in ?
    gp.ApplyPageTemplate(TemplatePage)
  File "D:\Program
Files\python\win32com\gen_py\6E73CA05-CE63-11CF-B59C-0000929132CEx0x1x0.py",
 line 1696, in ApplyPageTemplate
    return self._oleobj_.InvokeTypes(0x9c6, LCID, 1, (11, 0), ((12, 0),
(12, 16)),vTemplateName, vTemplateFileName)
com_error: (-2147352573, 'Member not found.', None, None)

>> 1)  My guess is that PythonCOM is sending the command "ApplyPageTemplate"
>> without the parameter, and then when SigmaPlots gets this it
>> balks and says
>> it needs the parameter.  This is consistent with the line
>> "sp.Notebooks.Add" working but "sp.Notebooks.Add()" not working.
>
>Can you post the complete traceback of the failure.
>

If instead of sp.Notebooks.Add in the above I run
sp.Notebooks.Add()

I get
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "D:\PythonCode\testSP21.py", line 7, in ?
    nb = sp.Notebooks.Add()
  File "D:\Program Files\python\win32com\client\dynamic.py", line 150, in
__call__
    return
self._get_good_object_(apply(self._oleobj_.Invoke,allArgs),self._olerepr_.de
faultDispatchName,None)
com_error: (-2147352573, 'Member not found.', None, None)

What I find particularly weird with the above is that if I type this in
interactively and watch SigmaPlot, as soon as I type in the
"sp.Notebooks.Add(", and before I type ")<cr>", I get a new notebook
appearing.  Then when I type ")<cr>", I get another notebook and the
traceback.

Tom
TA16@cornell.edu