Skip to main content
Solved

Mathematica set DoubleValue parameter

  • February 14, 2022
  • 2 replies
  • 173 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

Best answer by MichaelH

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;

}

View original
Did this topic help you find an answer to your question?

2 replies

  • Author
  • Infrared
  • 5 replies
  • February 14, 2022

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


MichaelH
Ansys Staff
Forum|alt.badge.img+2
  • Ansys Staff
  • 342 replies
  • Answer
  • February 14, 2022

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings