win32com problem

C

cfriedalek

I'm interacting with a third party application using python and com.
However having problems and don't know what to look at next to resolve
the issue.

The app. can be driven by VBS. The following VBS code works:

Set Synergy = CreateObject("synergy.Synergy")
Synergy.OpenProject "D:/temp/project.mpi"
Synergy.Project.OpenItemByName "test_bar_3d_6l_pc1", "Study"
Set Tet = Synergy.StudyDoc.GetFirstTet()
While Not Tet Is Nothing
Str = Tet.ConvertToString() + " "
Set Tet = Synergy.StudyDoc.GetNextTet(Tet)
MsgBox Str
WEnd

This prints "TE1" "TE2" etc


The "same" code in python returns <COMObject <unknown>> with each call
to the GetNextTet method.

import win32com.client
from win32com.client import Dispatch
Synergy = win32com.client.Dispatch("synergy.Synergy")
Synergy.OpenProject("D:/temp/project.mpi")
Synergy.Project.OpenItemByName("test_bar_3d_6l_pc1", "Study")
tet = Synergy.StudyDoc.GetFirstTet
while tet:
print str(tet)
tet = Synergy.StudyDoc.GetNextTet(tet)

Any clues on what I'm doing wrong, or how to investigate whether there
is a bug in win32com or in the third party apps com implementation.
 
S

Steve Holden

I'm interacting with a third party application using python and com.
However having problems and don't know what to look at next to resolve
the issue.

The app. can be driven by VBS. The following VBS code works:

Set Synergy = CreateObject("synergy.Synergy")
Synergy.OpenProject "D:/temp/project.mpi"
Synergy.Project.OpenItemByName "test_bar_3d_6l_pc1", "Study"
Set Tet = Synergy.StudyDoc.GetFirstTet()
While Not Tet Is Nothing
Str = Tet.ConvertToString() + " "
Set Tet = Synergy.StudyDoc.GetNextTet(Tet)
MsgBox Str
WEnd

This prints "TE1" "TE2" etc


The "same" code in python returns <COMObject <unknown>> with each call
to the GetNextTet method.

import win32com.client
from win32com.client import Dispatch
Synergy = win32com.client.Dispatch("synergy.Synergy")
Synergy.OpenProject("D:/temp/project.mpi")
Synergy.Project.OpenItemByName("test_bar_3d_6l_pc1", "Study")
tet = Synergy.StudyDoc.GetFirstTet

tet = Synergy.StudyDoc.GetFirstTet(), perhaps?
while tet:
print str(tet)
tet = Synergy.StudyDoc.GetNextTet(tet)

Any clues on what I'm doing wrong, or how to investigate whether there
is a bug in win32com or in the third party apps com implementation.

regards
Steve
 
C

cfriedalek

tet = Synergy.StudyDoc.GetFirstTet(), perhaps?

com_error: (-2147352573, 'Member not found.', None, None)

Sorry, should have mentioned that I tried that already. Any thoughts on
how to establish if the problem is with win32com or the 3rd party app?
 
A

Aries Sun

Have you tried late binding? Does late binding produce the same error?

Regards,

Aries
 
G

Gabriel Genellina

At said:
Set Tet = Synergy.StudyDoc.GetFirstTet()
tet = Synergy.StudyDoc.GetFirstTet

Can you see the difference...?


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
G

Gabriel Genellina

At said:
com_error: (-2147352573, 'Member not found.', None, None)

Sorry, should have mentioned that I tried that already. Any thoughts on
how to establish if the problem is with win32com or the 3rd party app?

Run it on the debugger step by step, and inspect all the intermediate objects.
Synergy.StudyDoc might be a function, by example, so you should add
another pair of ().
This is not obvious looking at the VB code.


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
C

cfriedalek

Gabriel said:
Run it on the debugger step by step, and inspect all the intermediate objects.
Synergy.StudyDoc might be a function, by example, so you should add
another pair of ().
This is not obvious looking at the VB code.

(Sorry, tied up this arvo so I could respond to your suggestion
earlier.)

Here's part of a debug session.

(Pdb) type(Synergy.StudyDoc)
<type 'instance'>

(Pdb) type(Synergy.StudyDoc.GetFirstTet)
<type 'instance'>

(Pdb) Synergy.StudyDoc.GetFirstTet
<COMObject <unknown>>

(Pdb) dir (Synergy.StudyDoc)
['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
'_Release_', '__A
ttrToID__', '__LazyMap__', '__call__', '__cmp__', '__doc__',
'__getattr__', '__g
etitem__', '__init__', '__int__', '__len__', '__module__',
'__nonzero__', '__rep
r__', '__setattr__', '__setitem__', '__str__', '_builtMethods_',
'_enum_', '_fin
d_dispatch_type_', '_get_good_object_', '_get_good_single_object_',
'_lazydata_'
, '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_',
'_print_details_
', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']

(Pdb) dir (Synergy.StudyDoc.GetFirstTet)
['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
'_Release_', '__A
ttrToID__', '__LazyMap__', '__call__', '__cmp__', '__doc__',
'__getattr__', '__g
etitem__', '__init__', '__int__', '__len__', '__module__',
'__nonzero__', '__rep
r__', '__setattr__', '__setitem__', '__str__', '_builtMethods_',
'_enum_', '_fin
d_dispatch_type_', '_get_good_object_', '_get_good_single_object_',
'_lazydata_'
, '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_',
'_print_details_
', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']

I'm pretty green with this kind of introspection (but willing to dig in
and learn). With the VBS code seems like GetFirstTet is a method of
StudyDoc that returns a variable which converted to string yields "TE1"
etc. But that doesn't seem to be true for python.

Is there any other way I can find out what attributes etc are available
to the GetFirstTet instance?

The type library is not supplied with the app. so if my basic
understanding is correct, I can't early bind.
 
C

cfriedalek

Problem solved.

Turns out it was a problem of mistranslating VBS code to Python.

The PYTHON line "print str(tet)" casts tet to a string and prints. This
is what I thought the VBS line "Str = Tet.ConvertToString()" was doing.
But of course "ConvertToString()" is a method of a Tet instance. So in
python the correct line should have been "print tet.ConvertToString".

Learning all the time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top