Skip to main content

I try to use code from example e23s08_py for changing settings of analysis window, but meet error with 

ray_settings.Field.UseAllFields()ray_settings.Wavelength.UseAllWavelengths()

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2023.1.2\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 126, in <module>
AttributeError: 'IAS_' object has no attribute 'Field'

    ray = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.RayFan)
ray_settings = ray.GetSettings()
ray_settings.NumberOfRays = max_rays / 2
ray_settings.Field.UseAllFields()
ray_settings.Wavelength.UseAllWavelengths()

ray.ApplyAndWaitForCompletion()
ray_results = ray.GetResults()

but even if I supress them   ray_settings.NumberOfRays = 0

dont change default value, silently. 

@Aleksandr.Makarov

 

If you are using pythonnet > 2.5.2, then you need to be aware of this:

In short, your code will almost work if you add .__implementation__ after your GetSettings():

ray = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.RayFan)
ray_settings = ray.GetSettings().__implementation__
ray_settings.NumberOfRays = max_rays / 2
ray_settings.Field.UseAllFields()
ray_settings.Wavelength.UseAllWavelengths()

ray.ApplyAndWaitForCompletion()
ray_results = ray.GetResults()

I am saying almost, because there’s something else you need to be cautious about. The number of rays need to be an integer. Therefore, I’d suggest to use:

ray_settings.NumberOfRays = int( max_rays / 2 )

or any other form of casting to integer.

I hope this helps and take care,

 

David


David

How I can change wave in analysis window?

I try few different but all of them was not correct: gee_settings.IAS_Wavelength = ZOSAPI.Analysis.Settings.EncircledEnergy.IAS_GeometricEncircledEnergy.Wavelength(1)

but it not work and I not sure how find proper key words for this case

    gee = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.GeometricEncircledEnergy)
gee_settings = gee.GetSettings().__implementation__


gee_settings.IAS_Wavelength = ZOSAPI.Analysis.Settings.EncircledEnergy.IAS_GeometricEncircledEnergy.Wavelength(1)



gee_settings.RadiusMaximum = 50
gee_settings.SampleSize = ZOSAPI.Analysis.SampleSizes.S_32x32
gee_settings.ReferTo = ZOSAPI.Analysis.Settings.EncircledEnergy.ReferToTypes.Centroid
gee_settings.Type = ZOSAPI.Analysis.Settings.EncircledEnergy.EncircledEnergyTypes.X_Only

gee.ApplyAndWaitForCompletion()

 


Your problem seems indeed to be related to a compatibility issue of the ZOSAPI with modern python versions.

If you don’t want to gain experience with casting variables between python and .NET,  ZOSPy could be a solution for you, as it performs all these steps automatically. It’s available through pypi or anaconda, and has quitea nice documentation


Your problem seems indeed to be related to a compatibility issue of the ZOSAPI with modern python versions.

If you don’t want to gain experience with casting variables between python and .NET,  ZOSPy could be a solution for you, as it performs all these steps automatically. It’s available through pypi or anaconda, and has quitea nice documentation

ZOSpy support all features of ZOS API? I cannot find GeometricEncircledEnergy


Dear Aleksandr,

 

The complete ZOSAPI can be accessed through ZOSPy, and ZOSPy will perform the conversion for all these functions (see https://zospy.readthedocs.io/en/latest/codecs.html  for a more elaborate explanation).

For some functions, ZOSPy also includes a more “easy”/pythonic way of performing an analysis, but not all possible Optic Studio analyses are (yet) included. If you require another analysis, you can modify one of the analyses that are already included as a template (see for example the polarisation analysis which has been contributed by one of the ZOSPy users). 

If you have made something that works nice, please consider contributing it, so your fellow OpticStudio users can benefit from it. 


gee_settings.Wavelength.SetWavelengthNumber(1)


David.Nguyen how I can change settings in loop?

I tried all separators. between X and Only but no success

type_s = "X Only", "Y Only"]

for type_ in type_s:

gee_settings.Type = ZOSAPI.Analysis.Settings.EncircledEnergy.EncircledEnergyTypesstype_]
 

@Aleksandr.Makarov 

 

This works for me (don’t forget the usual .__implementation__):

type_s = sZOSAPI.Analysis.Settings.EncircledEnergy.EncircledEnergyTypes.X_Only, ZOSAPI.Analysis.Settings.EncircledEnergy.EncircledEnergyTypes.Y_Only]
for type_ in type_s:
my_analysis = TheSystem.Analyses.New_GeometricEncircledEnergy()
my_analysis_settings = my_analysis.GetSettings().__implementation__
my_analysis_settings.Type = type_
my_analysis.ApplyAndWaitForCompletion()

Take care,

 

David


Reply