Using Iron Python with Solidworks API

こ雲淡風輕ζ 提交于 2019-12-06 16:07:29

Simplifying a bit:

In .NET, and in COM, you don't normally create instance by directly calling the constructor of a class. In fact, most services don't even expose the actual class. Instead, they expose an interface—that is, an abstract type which is a supertype of the actual class, and just defines the public methods they want you to have—and then either (a) a factory function that generates an instance of some concrete subclass of that interface, or (b) a concrete class that COM can use in "automatic factory" functions like CreateObject.

That's what the docs mean when they say:

Use CreateObject, GetObject, New, or similar functions to obtain the ISldWorks object from a Dispatch application (Visual Basic or C++ Dispatch). Standalone .exe C++ COM applications can use CoCreateInstance.

CreateObject takes a "ProgID", a string representing a concrete type name, and does all the magic needed to get a concrete type from that name, pass it through .NET/COM interop, ask the service to create an object of that concrete type, verify that it matches the appropriate interface, and wrap it up. If there's an example of using SolidWorks from VB.NET, it will probably use CreateObject, and you can do the same thing from IronPython.

However, really, at some point you're going to need to read some documentation on .NET and understand what all of it means.

Jiang Yu

I am wondering if this question was settled, but still post sth here. Like other apps using COM, simply type:

swApp = Dispatch("sldworks.Application")

By doing this, you get access to Solidworks, and you can use APIs to do what you want. Hope this will help, whoever needs it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!