win32com problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cfriedalek@gmail.com

    #1

    win32com problem

    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("s ynergy.Synergy" )
    Synergy.OpenPro ject "D:/temp/project.mpi"
    Synergy.Project .OpenItemByName "test_bar_3d_6l _pc1", "Study"
    Set Tet = Synergy.StudyDo c.GetFirstTet()
    While Not Tet Is Nothing
    Str = Tet.ConvertToSt ring() + " "
    Set Tet = Synergy.StudyDo c.GetNextTet(Te t)
    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("syne rgy.Synergy")
    Synergy.OpenPro ject("D:/temp/project.mpi")
    Synergy.Project .OpenItemByName ("test_bar_3d_6 l_pc1", "Study")
    tet = Synergy.StudyDo c.GetFirstTet
    while tet:
    print str(tet)
    tet = Synergy.StudyDo c.GetNextTet(te t)

    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.

  • Steve Holden

    #2
    Re: win32com problem

    cfriedalek@gmai l.com wrote:
    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("s ynergy.Synergy" )
    Synergy.OpenPro ject "D:/temp/project.mpi"
    Synergy.Project .OpenItemByName "test_bar_3d_6l _pc1", "Study"
    Set Tet = Synergy.StudyDo c.GetFirstTet()
    While Not Tet Is Nothing
    Str = Tet.ConvertToSt ring() + " "
    Set Tet = Synergy.StudyDo c.GetNextTet(Te t)
    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("syne rgy.Synergy")
    Synergy.OpenPro ject("D:/temp/project.mpi")
    Synergy.Project .OpenItemByName ("test_bar_3d_6 l_pc1", "Study")
    tet = Synergy.StudyDo c.GetFirstTet
    tet = Synergy.StudyDo c.GetFirstTet() , perhaps?
    while tet:
    print str(tet)
    tet = Synergy.StudyDo c.GetNextTet(te t)
    >
    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
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://holdenweb.blogspot.com
    Recent Ramblings http://del.icio.us/steve.holden

    Comment

    • cfriedalek@gmail.com

      #3
      Re: win32com problem

      tet = Synergy.StudyDo c.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?

      Comment

      • Aries Sun

        #4
        Re: win32com problem

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

        Regards,

        Aries

        cfriedalek@gmai l.com wrote:
        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("s ynergy.Synergy" )
        Synergy.OpenPro ject "D:/temp/project.mpi"
        Synergy.Project .OpenItemByName "test_bar_3d_6l _pc1", "Study"
        Set Tet = Synergy.StudyDo c.GetFirstTet()
        While Not Tet Is Nothing
        Str = Tet.ConvertToSt ring() + " "
        Set Tet = Synergy.StudyDo c.GetNextTet(Te t)
        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("syne rgy.Synergy")
        Synergy.OpenPro ject("D:/temp/project.mpi")
        Synergy.Project .OpenItemByName ("test_bar_3d_6 l_pc1", "Study")
        tet = Synergy.StudyDo c.GetFirstTet
        while tet:
        print str(tet)
        tet = Synergy.StudyDo c.GetNextTet(te t)
        >
        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.

        Comment

        • Gabriel Genellina

          #5
          Re: win32com problem

          At Tuesday 24/10/2006 22:15, cfriedalek@gmai l.com wrote:
          >Set Tet = Synergy.StudyDo c.GetFirstTet()
          >tet = Synergy.StudyDo c.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

          Comment

          • Gabriel Genellina

            #6
            Re: win32com problem

            At Tuesday 24/10/2006 23:20, cfriedalek@gmai l.com wrote:
            tet = Synergy.StudyDo c.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?
            Run it on the debugger step by step, and inspect all the intermediate objects.
            Synergy.StudyDo c 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

            Comment

            • cfriedalek@gmail.com

              #7
              Re: win32com problem


              Gabriel Genellina wrote:
              Run it on the debugger step by step, and inspect all the intermediate objects.
              Synergy.StudyDo c 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.St udyDoc)
              <type 'instance'>

              (Pdb) type(Synergy.St udyDoc.GetFirst Tet)
              <type 'instance'>

              (Pdb) Synergy.StudyDo c.GetFirstTet
              <COMObject <unknown>>

              (Pdb) dir (Synergy.StudyD oc)
              ['_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_obje ct_', '_get_good_sing le_object_',
              '_lazydata_'
              , '_make_method_' , '_mapCachedItem s_', '_oleobj_', '_olerepr_',
              '_print_details _
              ', '_proc_', '_unicode_to_st ring_', '_username_', '_wrap_dispatch _']

              (Pdb) dir (Synergy.StudyD oc.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_obje ct_', '_get_good_sing le_object_',
              '_lazydata_'
              , '_make_method_' , '_mapCachedItem s_', '_oleobj_', '_olerepr_',
              '_print_details _
              ', '_proc_', '_unicode_to_st ring_', '_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.

              Comment

              • cfriedalek@gmail.com

                #8
                Re: win32com problem - Problem Solved

                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.ConvertToSt ring()" was doing.
                But of course "ConvertToStrin g()" is a method of a Tet instance. So in
                python the correct line should have been "print tet.ConvertToSt ring".

                Learning all the time.

                Comment

                Working...