Help with Python COM Type Mismatch
Markus Wankus
markus_wankus at hotmail.com
Sat Dec 14 20:07:35 EST 2002
On 13 Dec 2002 20:55:38 GMT, Uwe Schmitt <uwe.schmitt at procoders.net> wrote:
> Markus Wankus <markus_wankus at hotmail.com> wrote:
> > Well, I received a lot of help from Mark on this one, and finally have
> > figured things out. If anyone is interested, let me know and I will
> > share my experiences.
>
> Yes, I'm interested.
>
> Greetings, Uwe.
>
>
Well, I will try to sum up. I was dealing with an API (Solidworks) which apparently is not "normal" and is similar to Lotus
Notes in it's stupidness. It has a well-defined type library but seemed to know nothing about it when you tried to use it.
I was using early bindings with gencache, but it didn't seem to be having any effect. So, what I was doing was this:
#<start of Python code>
from win32com.client import Dispatch, gencache, constants, pythoncom
sldmod = gencache.EnsureModule('{83A33D31-27C5-11CE-BFD4-00400513BB57}', 0, 10, 0)
# Attach to Solidworks
sldwrks = Dispatch("SldWorks.Application")
print repr(sldwrks)
part = sldwrks.ActiveDoc
a, b = sldwrks.OpenDocSilent(r'E:\SolidData\Detail Drawings\C00-000421.SLDDRW', swDocDRAWING)
#<end of Python code>
This code attaches to Solidworks, gets the Active document open, then it
fails - telling me the last argument to OpenDocSilent() is not optional. There were also other various methods giving me
weird errors about Unicode until I tried specifying the methods without the brackets - then it would work.
The key here is the "print repr(sldwrks)" above produced:
<COMObject SldWorks.Application>
Indicating early binding was not happening. It was suggested I try the following instead:
#<start of Python code>
from win32com.client import Dispatch, gencache, constants, pythoncom
sldmod = gencache.EnsureModule('{83A33D31-27C5-11CE-BFD4-00400513BB57}', 0, 10, 0)
# Attach to Solidworks
sldwrks = Dispatch("SldWorks.Application")
sldwrks = sldmod.ISldWorks(sldwrks)
part = sldmod.IModelDoc(sldwrks.ActiveDoc)
(...same code as before after this point)
This worked. Notice that for every object I create, I pass what *should* work, to the constructor of the interface - and I
magically get back a proper object.
Anyway, I still don't know much about this whole COM thing, but at least this part of it works now!
Regards,
--
Markus.
More information about the Python-list
mailing list