win32com and com Record types

M

Mike Margerum

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.MasterIndex & " " & brandRec.Id & " " &
brandRec.Description

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:\temp\irx2_brand.pdb")
for i in range(0,db.RecordCount):
print i

Thanks a lot for the help.
 
M

Mark Hammond

Mike said:
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.MasterIndex & " " & brandRec.Id & " " &
brandRec.Description

You can create a record object by using:

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

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

See win32com\test\testvb for some real examples.

Mark.
 
C

Chuck Spears

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.client.Dispatch("PDBUtils.BrandDb")
db.Open (r"c:\temp\irx2_brand.pdb")
for i in range(0,db.RecordCount):
print i
rec = win32com.client.Record("BrandRecord", db)


0
Traceback (most recent call last):
File "c:\temp\test\comTest.py", line 18, in ?
rec = win32com.client.Record("BrandRecord", db)
File "C:\PYTHON22\lib\site-packages\win32com\client\__init__.py",
line 392, in Record
object = gencache.EnsureDispatch(object)
File "C:\PYTHON22\lib\site-packages\win32com\client\gencache.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
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top