Settings syntax for python

  • 25 October 2020
  • 3 replies
  • 169 views

I am trying to write an interactive extension using the COM (not .NET) framework, and need to change some settings. I have read through (and watched the videos) regarding navigating the API Syntax Help tool, and have spent considerable time scanning the forum and the sample code for guidance.


Specifically, I am using the FFT PSF Cross Section analysis, and want to change the Type: to X-Linear or Y-Linear, like this:



To try and sort this out, I tried to do the exact same thing as one does in setting the 'Refer To' field in the Standard Spot diagram (it is also an Analysis window with a drop-down menu of fixed selections) I found the following code snippet in example 22:


    spot = TheSystem.Analyses.New_Analysis(constants.AnalysisIDM_StandardSpot)

    spot_setting = spot.GetSettings()

    baseSetting = CastTo(spot_setting, 'IAS_Spot')

    baseSetting.Field.SetFieldNumber(0)

    baseSetting.Wavelength.SetWavelengthNumber(0)

    baseSetting.ReferTo = constants.ReferTo_Centroid


Here is the relevant part of the API help tool and the associated code:



Here is the same thing for setting the FFT PSF Cross Section type to Y_Linear:



By exact analogy to the Standard Spot settings, I tried the following code (and at least a half-dozen variants), without success:


fftc = TheAnalyses.New_Analysis(constants.AnalysisIDM_FftPsfCrossSection)

fftc_setting = fftc.GetSettings()

baseFftcSet = CastTo(fftc_setting, 'IAS_FftPsfCrossSection')

baseFftcSet.Field.SetFieldNumber(2)

baseFftcSet.Wavelength.SetWavelengthNumber(1)

baseFftcSet.Type = constants.Type_Y_Linear


The SetFieldNumber and SetWavelengthNumber commands work, but the last line throws a 'AttributeError: Type_Y_Linear' error. By the way, I did spot that the Zemax GUI uses dashes: 'X-Linear', whereas the API reference is an underscore: 'X_Linear'. This is among the many variants I attempted.


Any ideas?


Thanks,


Tom Herbst


 


3 replies

Userlevel 5
Badge +1

Hey Tom,


Thanks for posting on the forums! It looks like the issue you're running into is specifically related to how the .COM interface is interacting with the ZOS-API. What's happening is that the AttributeError you're seeing is due to some translation inconsistencies from the pywin32 module used to translate the .NET interface into .COM. This was done to make it compatible with Python in prior releases, but as of OS 20.2.2, we have introduced .NET functionality with Python, which sidesteps the issue you are directly running into.


Specifically for your issue, I would highly recommend checking out this forum post, as my colleague Julia put together a way to check for these translation errors to identify what needs to be changed to fix your settings. In your particular case, I can apply the '_prop_map_get.keys()' function to baseFftcSet to obtain the properties for the FFT PSF Cross Section settings. We'll see that we actually need to use type rather than Type to modify this property:

 




 


Second, we want to check the enumeration structure for the Type properties in the FFT PSF Cross Section settings. In our ZOS-API Syntax Guide, we can see that the structure for the cross section PSF analyses are a bit different from your usage:

 



For completeness, though, you can also check that there are no translation errors with a method also shown in Julia's post, which is to output the enumeration in a text format:

 




 


So, the syntax needed for changing your data to Y-Linear would be


baseFftcSet.type = constants.PsfTypes_Y_Linear



Again, if you are not totally limited to using the .COM interface with the ZOS-API and Python connectivity, we highly recommend using the .NET interface. Otherwise, you can refer to the forum post I linked to (which also has additional posts with very helpful tips/explanations) for some techniques in checking the syntax.


Let us know if you have any more questions here!


~ Angel

Hi Angel,


Thanks for the response. It seems clear that using the API help tool under under the .COM interface is not a good idea. The info in Julia's post is a great help, but I suppose that I will have to bite the bullet and switch to .NET.


I have hesitated so far, since I am a linux/Mac person (I use OpticStudio over Microsoft Remote Desktop) and am not sure how to install the bare minimum infrastructure to get .NET working. My initial explorations seemed to indicate that I would have to install many gigabytes of infrastructure.


Thanks again,


Tom


 

Userlevel 5
Badge +1

Hi Tom!


Thanks for your follow up here. I do think there are several benefits to using the .NET interface with Python. As for installing the infrastructure, though I am not directly aware of how large the modules you'll need to install are (it has been awhile since I've installed everything on my machine), you can also read through the article ZOS-API using Python.NET for some more instructions on getting the .NET interface. If you are already using Python, you just need to install the modules via PIP. You might have seen that article already from the prior forum thread I linked to, but I wanted to include it here just in case.


Let us know if you have any further questions here!


~ Angel

Reply