简体   繁体   中英

Creating new Python object when using win32COM

I'm using win32COM to send commands to a software called "Robot Structural Analysis". I am able to retrieve objects that is declared inside the application, but I cannot find a way to declare new instance of a class defined in the application's API.

For example: robot = win32.gencache.EnsureDispatch("Robot.Application")

(What I can do is) l = robot.dataserver.somelist

However, in the api guidebook, there is a class named, say, XData, and I want to create a new instance of that class. What most people usually do with Excel VBA is

Dim x As New XData
x.property1 = 1
x.property2 = 2
...

But Python doesn't require declaring variable type. How can I do this using Python?

To create a new class instance defined in the API using win32com and Python, one can do the followings:

  1. Windows Start -> run regedit (Registry Editor)-> HKEY_CLASSES_ROOT : Here shows all the names of COM objects, such as Robot.GeoContour

  2. In the Python code, the class instance should be declared as: contour = win32.DispatchEx("Robot.GeoContour")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM