[英]Creating new Python object when using win32COM
I'm using win32COM to send commands to a software called "Robot Structural Analysis".我正在使用 win32COM 向名为“机器人结构分析”的软件发送命令。 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.我能够检索在应用程序内部声明的对象,但我找不到一种方法来声明应用程序 API 中定义的类的新实例。
For example: robot = win32.gencache.EnsureDispatch("Robot.Application")
例如: robot = win32.gencache.EnsureDispatch("Robot.Application")
(What I can do is) l = robot.dataserver.somelist
(我能做的是) 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.但是,在 api 指南中,有一个名为 XData 的类,我想创建该类的新实例。 What most people usually do with Excel VBA is大多数人通常用 Excel VBA 做的是
Dim x As New XData
x.property1 = 1
x.property2 = 2
...
But Python doesn't require declaring variable type.但是 Python 不需要声明变量类型。 How can I do this using Python?我如何使用 Python 做到这一点?
To create a new class instance defined in the API using win32com and Python, one can do the followings:要使用 win32com 和 Python 创建在 API 中定义的新类实例,可以执行以下操作:
Windows Start -> run regedit (Registry Editor)-> HKEY_CLASSES_ROOT : Here shows all the names of COM objects, such as Robot.GeoContour Windows Start -> run regedit (Registry Editor)-> HKEY_CLASSES_ROOT : 这里显示所有COM对象的名称,比如Robot.GeoContour
In the Python code, the class instance should be declared as: contour = win32.DispatchEx("Robot.GeoContour")在 Python 代码中,类实例应声明为:contour = win32.DispatchEx("Robot.GeoContour")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.