win32com and com Record types

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Margerum

    win32com and com Record types

    Hi I am trying to using a COM server I built in C++. I ran GenPy on
    my type library and I am able to instantiate objects from the server.
    What I can't figure out is how to create/use Record types from my COM
    server. I see them defined in my generated py file as a map

    RecordMap = {
    'FormRecord': '{F6EBBC2A-E2D5-4921-A498-EA80AE851012}',
    'ICD9Record': '{FA83723F-55F6-4D17-8309-A9D323A4FD01}',
    'BrandRecord': '{AD4B5647-E78A-447B-A041-EEC59E89D3F6}',
    }

    How Do i instantiate one so I can use it in one of my methods that
    takes a BrandRecord by reference?

    This is a snippet of VB code that works

    Dim db As New BrandDb
    db.Open ("c:\temp\irx2_ brand.pdb")
    Dim brandRec As BrandRecord
    While i < db.RecordCount
    db.GetBrand i, brandRec, 1 'use 0 instead of 1 to not load
    form data
    List1.AddItem brandRec.Master Index & " " & brandRec.Id & " " &
    brandRec.Descri ption

    This is my python code that is working minus the GetBrand call

    from win32com.client import *
    from PDBUtils import *
    db = BrandDb()
    print db.Version
    db.Open(r"c:\te mp\irx2_brand.p db")
    for i in range(0,db.Reco rdCount):
    print i

    Thanks a lot for the help.
  • Mark Hammond

    #2
    Re: win32com and com Record types

    Mike Margerum wrote:[color=blue]
    > Hi I am trying to using a COM server I built in C++. I ran GenPy on
    > my type library and I am able to instantiate objects from the server.
    > What I can't figure out is how to create/use Record types from my COM
    > server. I see them defined in my generated py file as a map
    >
    > RecordMap = {
    > 'FormRecord': '{F6EBBC2A-E2D5-4921-A498-EA80AE851012}',
    > 'ICD9Record': '{FA83723F-55F6-4D17-8309-A9D323A4FD01}',
    > 'BrandRecord': '{AD4B5647-E78A-447B-A041-EEC59E89D3F6}',
    > }
    >
    > How Do i instantiate one so I can use it in one of my methods that
    > takes a BrandRecord by reference?
    >
    > This is a snippet of VB code that works
    >
    > Dim db As New BrandDb
    > db.Open ("c:\temp\irx2_ brand.pdb")
    > Dim brandRec As BrandRecord
    > While i < db.RecordCount
    > db.GetBrand i, brandRec, 1 'use 0 instead of 1 to not load
    > form data
    > List1.AddItem brandRec.Master Index & " " & brandRec.Id & " " &
    > brandRec.Descri ption[/color]

    You can create a record object by using:

    r = win32com.client .Record("Record Name", object)

    where "RecordName " is the name of the record, and 'object' is &any* COM
    object defined in the same type library.

    See win32com\test\t estvb for some real examples.

    Mark.

    Comment

    • Chuck Spears

      #3
      Re: win32com and com Record types

      When I run this code, it fails on the line where i try to create a
      record. Thanks again for the help.

      import win32com.client
      db=win32com.cli ent.Dispatch("P DBUtils.BrandDb ")
      db.Open (r"c:\temp\irx2 _brand.pdb")
      for i in range(0,db.Reco rdCount):
      print i
      rec = win32com.client .Record("BrandR ecord", db)


      0
      Traceback (most recent call last):
      File "c:\temp\test\c omTest.py", line 18, in ?
      rec = win32com.client .Record("BrandR ecord", db)
      File "C:\PYTHON22\li b\site-packages\win32c om\client\__ini t__.py",
      line 392, in Record
      object = gencache.Ensure Dispatch(object )
      File "C:\PYTHON22\li b\site-packages\win32c om\client\genca che.py",
      line 442, in EnsureDispatch
      raise TypeError, "This COM object can not automate the makepy
      process - please run makepy manually for this object"
      TypeError: This COM object can not automate the makepy process -
      please run makepy manually for this object

      Comment

      Working...