Solved

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

  • 21 May 2020
  • 1 reply
  • 340 views

Userlevel 6
Badge +2

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?

icon

Best answer by Allie 21 May 2020, 00:50

View original

1 reply

Userlevel 6
Badge +2

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. Note: Click on the image for a higher resolution version of these images.

 

 

2. 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:

 

 

Note: The graphics are re-sized to fit within the proportions of the Forum. You may right-click on the image and open it in a new tab for a higher-quality view. 

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!

Reply