Skip to main content

In OpticStudio interface, If the optical system has some error then just after opening we get the error messages in Zemax Error Message Box .As we can see in image below ,SK2 was excluded before user setting .

In ZOS-API, there are some methods under the ZOSAPI.IOpticalSystem Interface Reference that allows to zemax error messages: 

The general workflow is to whatever operation will generate the message you need to call  TheSystem.GetCurrentStatus() .It will show the status of your optical setup .

Here sample code for Matlab :

import ZOSAPI.*; 
TheSystem = TheApplication.PrimarySystem;
sampleDir = TheApplication.SamplesDir;
testFile = System.String.Concat('C:\test\Double Gauss 28 degree field.zmx');
test = char(TheSystem.GetCurrentStatus())

Here’s sample code for Python  : 

# Insert Code Here

# Setup
testFile =r"C:\test\Double Gauss 28 degree field.zos"
TheSystem.LoadFile(testFile,False)
# To get the Error message
test = str(TheSystem.GetCurrentStatus())
print(test)

I create a connection with the Interactive Extension for Python and Matlab both .In this screenshot we can the Zemax Error Message displayed :
 

Sahil Rajan

Thanks @Sahil!

In addition to this, we have a few other methods for checking errors in the API. I have compiled a list from previous cases. These are various methods for either ensuring the file loaded properly or for making sure there are no major system errors. Note: I am copying these from another post I made with the same content, but I think it will be good to compile this list here. 

1. The most straightforward: query some information about surface 1 in the LDE or object 1 in the NSCE. Usually checking Radius or Thickness will work. That will let you know if the file loaded properly.

2. Call TheSystem.GetCurrentStatus() immediately before and after each change to the system that could potentially cause an error in the system and therefore prevent the system from updating correctly.

3. Use the message logging functions from within the TheApplication Interface:

 

210428-111827-image.png

 

These properties basically toggle whether or not transient error messages are stored in a collection for retrieval.

4. If a property or public member function is of the type IMessage then an error will be returned if the function fails to run. One example is the MakeDoublePass tool in the ILensDataEditor Interface. This tool is an IMessage type:

 

210428-111905-image.png

 

When an LDE-based tool (like Make Double Pass) runs successfully, it will return null. When it is not able to run, it will return an IMessage interface. This interface contains two items:

  1. ErrorCode (an enumerated list of potential problems)
  2. Text (a string output of the encountered error message)

To make sure your tool has run, you can use the following line:

 

val = TheLDE.RunTool_MakeDoublePass(4);

 

Adding a variable val as a placeholder will allow you to build an IF statement which checks to see if val is empty or not. If the tool fails to run, you can access the errors with the following:

 

error = char(val.ErrorCode);

message = char(val.Text);

 


Reply