Hi All,
I’ve been trying to write a Python Interactive Extension with the ZOS-API. Having started with the boilerplate generated through the GUI at Programming > Python > Interactive Extension, I appended the following code at the end of the generated file:
# Insert Code Here
import typing
psfWindow = TheSystem.Analyses.New_HuygensPsf()
settings = typing.cast(psfWindow.GetSettings(),ZOSAPI.Analysis.Settings.Psf.IAS_HuygensPsf)
field = settings.Field
field = typing.cast(field, ZOSAPI.Analysis.Settings.IAS_Field)
print(str(field.GetFieldNumber()))
When I run this (having clicked on the Interactive Extension button as per the documentation), the following gets printed:
Found OpticStudio at: %sc:\program files\zemax opticstudio Connected to OpticStudio Serial #: L118546
Traceback (most recent call last): File "C:\Users\dshteinbok\Documents\Zemax\ZOS-API Projects\PythonZOSConnection1\PythonZOSConnection1.py", line 114, in <module> print(str(field.GetFieldNumber())) TypeError: not enough arguments
I am trying to access the method ZOSAPI.Analysis.Settings.IAS_Field.GetFieldNumber() which is detailed in the included documentation and shouldn’t take any arguments. To investigate, I replaced the last line in the python code I gave above (the one that is actually calling GetFieldNumber()) with a line to investigate its __str__ method:
print(field.GetFieldNumber)
I got the output:
Found OpticStudio at: %sc:\program files\zemax opticstudio Connected to OpticStudio Serial #: L118546 <unbound method 'GetFieldNumber'>
That last line, “unbound method” makes it seem as though the method isn’t working because the name of the function is not bound to anything. This makes me wonder: was casting field
as I did the wrong thing to do? What would be the proper approach?
By the way, I tried omitting the line that casts field
to type IAS_Field
, but having done this I got the error: AttributeError: 'PropertyObject' object has no attribute 'GetFieldNumber'
Am I using the API incorrectly? How would you go about doing this (just getting the field number used in the Huygens PSF function)?
Thanks,
Daniel