Solved

Mathematica set DoubleValue parameter

  • 14 February 2022
  • 2 replies
  • 128 views

I am able to control IntegerValue parameters of objects in ZEMAX from Mathematica

theSystem@NCE@GetObjectAt[8]@GetObjectCell[ObjectColumn`Par2]@IntegerValue = 512;

 

however DoubleValue object returns an error

theSystem@NCE@GetObjectAt[1]@GetObjectCell[ObjectColumn`Par6]@DoubleValue = 10.1;

 

NET::netexcptn: A .NET exception occurred: System.ArgumentException: Expected Double, got 'String'
   at ZemaxUI.ZOSAPI.Editors.ZOSAPI_EditorCellBase.set_DoubleValue(Double value).

 

What is the syntax  to control a DoubleValue object?

 

Thank and BR,

Jozef

icon

Best answer by MichaelH 14 February 2022, 21:53

View original

2 replies

solved my question .. i was looking into wrong parameter (pobjects Par6 was not a DoubleValue). 

Userlevel 6
Badge +2

Hi Jozef,

When I’m dealing with changing cells in an editor that could take multiple values (i.e. the parameters in the LDE/NCE or the Hx/Hy/Px/Py/Ex/Ey columns in the MFE), I always like to wrap my cell assignment in a short switch statement.  All cells in the API can have 1 of 3 values:

  • ZOSAPI.Editors.CellDataType.Integer
  • ZOSAPI.Editors.CellDataType.Double
  • ZOSAPI.Editors.CellDataType.String

If the current is expecting a different data type than what you are assigning, you will get the error you saw.  A short pseudo-code (sorry, I don’t know Mathematica) would then look like:

switch(cell.DataType){

   case ZOSAPI.Editors.CellDataType.Integer:

      cell.IntegerValue = val; break;

   case ZOSAPI.Editors.CellDataType.Double:

      cell.DoubleValue = val; break;

   case ZOSAPI.Editors.CellDataType.String:

      cell.Value = val; break;

}

Reply