Zernike Alteration in Python API

  • 10 September 2020
  • 5 replies
  • 71 views

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?


5 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

Best,

Ali

Thanks Ali,

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

Chase

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

Best,

Ali

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

Reply