What is the difference between Python COM and Python .NET?

aculler_16
aculler_16 Member, Moderator, Employee Posts: 9
First Comment Ansys Employee
✭✭✭

With the OpticStudio 20.2 release, the way we connect to Python has changed from using the COM interface to using .NET. Are there any differences in how the API code is implemented in Python after this change?

Best Answer

  • aculler_16
    aculler_16 Member, Moderator, Employee Posts: 9
    First Comment Ansys Employee
    ✭✭✭
    Answer ✓

    In general, there are two major differences between Python COM and Python .NET:

    1. In the COM setup, you need to use CastTo to use properties belonging to an alternate interface. For example, when running a ray trace in Non-Sequential Mode through the API, the ray trace is set up using the INSCRayTrace interface. To run the ray trace, the property Run is used, which belongs to the ISystemTool interface. In Python COM, we are forced to explicitely call the ISystemTool interface using the CastTo command. This is not necessary in .NET. I have provided a side-by-side comparison below.

    1. In the COM setup, enumerated variables are stored in the constants library. This means we can call an enumerated variable by typing something like constants.EnumeratedVariable_Enumeration. In the .NET interface, the enumerated variables use their full title (as displayed in the Help System) instead of using the constants library. I have provided an example of this below:

    If you haven't already, take a look at our overview of Python .NET in the Knowledgebase: 'ZOS-API using Python.NET.' In that article, the differences I have discussed above are outlined. We also provide a step-by-step guide on setting up this new interface!