Solved

Using Zemax features through python.

  • 11 October 2023
  • 2 replies
  • 235 views

Hi Team,

 

I have a python program that finds the shifts in the position of spots (consider it as focused spots). I want to connect my python program with Zemax (Through Interactive Extension script)

 

My question is, how do I connect specific feature (Say- Geometrical I mage analysis or Spot diagram) with python? Also, is there any changes I should be making in my python code, to connect with these Zemax features?

 

Thanks in advance.

 

Regards,

Arun

icon

Best answer by David.Nguyen 11 October 2023, 14:41

View original

2 replies

Userlevel 7
Badge +2

Hi @Aruntv,

 

There are general resources, such as:

I’d like to also mention ZOSPy:

which is built on top of the ZOS-API, and enables more Pythonic access to OpticStudio.

The only Python requirement is the Pythonnet module, and you might want to be aware of this issue:

Now more specificaly, if you want interact with an analysis using the ZOS-API Interactive Extension, its important to assess the state of implementation of this analysis. There are mainly two things to checks.

First, analyses have a property called HasAnalysisSpecificSettings, which indicates whether you can modify the settings of said analysis directly from the ZOS-API (instead of going through a settings file). You can do it for a geometric image analysis:

geo_imag = TheSystem.Analyses.New_GeometricImageAnalysis()

print(geo_imag.HasAnalysisSpecificSettings)

and it will return True. This indicates that the geometric image analysis settings have been fully implemented in the ZOS-API. You can fill the full list of settings in the Syntax Help File, but I’m also copying them here for your reference:

and here’s an example:

geo_imag = TheSystem.Analyses.New_GeometricImageAnalysis()

geo_imag_settings = geo_imag.GetSettings().__implementation__

geo_imag_settings.Field.SetFieldNumber(1)
geo_imag_settings.RaysX1000 = 10
geo_imag_settings.UsePolarization = True

geo_imag.ApplyAndWaitForCompletion()

Second, you need to check how to retrieve the results of the analysis. For that, you need to check what is returned by the GetResults() method. But, for geometric image analysis, these have not been implemented yet (to the best of my knowledge). Therefore, you need to save the results as a text file and parse it. You can save the results as a text file like so:

geo_imag_results = geo_imag.GetResults()
geo_imag_results.GetTextFile(r'E:\geo_imag_results.txt')

This creates a text file that contains the results of geometric image analysis, and then you can use Python to parse it and retrieve it in a Numpy array for example.

I hope this helps.

Take care,

 

David

 

Thanks David, this is useful. Let me try this out.

I appreciate your effort.

 

Regards,

Arun

Reply