Zernike Alteration in Python API

  • 10 September 2020
  • 6 replies

Does anyone have an example (or is there one in the zemax documentation) for altering the number of zernike terms and the terms themselves using a python API?


Best answer by Ali H 10 September 2020, 11:40

View original

6 replies

Badge +1

Hi Chase,

You may use code similar to below to get/set the number of Zernike terms and set the values of the coefficients:

TheLDE = TheSystem.LDE
surf3 = TheLDE.GetSurfaceAt(3)
surf3.SurfaceData.NumberOfTerms = 5
surf3.GetSurfaceCell(ZOSAPI.Editors.LDE.SurfaceColumn.Par15).DoubleValue = 5.3



Thanks Ali,

Does it work similarily in Non-sequential? Also, what is the command for reading the parameter that is already there?


Badge +1

Hi Chase,

Yes, it is similar in non-sequential . The code in NSC for a Zernike Surface as Object number 3 would be:

TheNCE = TheSystem.NCE
obj3 = TheNCE.GetObjectAt(3)
numTerms = obj3.ObjectData.NumberOfZTerms
Z1 = obj3.GetObjectCell(ZOSAPI.Editors.NCE.ObjectColumn.Par16).DoubleValue

The above code gets the values that are currently set for the number of terms and Z1. Just to clarify:

to get a value and assign it to the variable Z1 you could use:

Z1 = obj3.GetObjectCell(ZOSAPI.Editors.NCE.ObjectColumn.Par16).DoubleValue

to set a value you could use:

obj3.GetObjectCell(ZOSAPI.Editors.NCE.ObjectColumn.Par16).DoubleValue = 3.0



Awesome, Thank you!

This code did not work for me.  Did something change in the API?
I get an error:

System.ArgumentException: Expected Double, got 'String'
   at ZemaxUI.ZOSAPI.Editors.ZOSAPI_EditorCellBase.set_DoubleValue(Double value)

for the line: 

surf3.GetSurfaceCell(ZOSAPI.Editors.LDE.SurfaceColumn.Par15).DoubleValue = 5.3
Userlevel 2
Badge +2


That line of code should still work. Double check that there aren’t any strange characters (possibly white space) that were appended if you copy and pasted it straight out of the post. My first impression is that it is acting like 5.3 is a string, so just make sure that it is indeed interpreted as a Double.

If that doesn’t work, can you share a larger snippet of your code so that we can check for errors?