Skip to main content

Hello, I am trying to use the ZOS-API through Python. I have found the knowledgebase articles to be very scattered and confusing. I would like to access the dictionary of enumeration constants referenced multiple times in the linked article. However, the article does not show how to find the constants dict within ZOS-API. And, the source script for the code snippets is not linked in the article attachments! Does anyone know how I can access the constants dict through python? Thanks in advance.

https://support.zemax.com/hc/en-us/articles/1500005576662-ZOS-API-using-Python

Hi @Julian.Irwin,

The article you have linked refers to Python COM. Prior to OpticStudio 20.2, this method was used to connect Python to the ZOS-API. The constants dictionary is something unique to that connection method. 

If you are using Python in a later version of OpticStudio, then enumerated variables are accessed via the name of the enumeration. I discuss this in more depth here: 

 

Thanks for bringing this up - I’ll see to it that the articles referring to PythonCOM are updated with a warning. 

In the meantime - if you are learning the ZOS-API, I recommend taking a look at this free learning plan: Getting Started with ZOS-API – Zemax. In particular, the articles under Fundamentals of structure and syntax are very useful in learning about the different variable types within the API. This will help teach you how to find enumerated variables within the help system. 

In addition to this, we also provide several sample files with your OpticStudio download. Find the folder C:\Users\...\Documents\Zemax\ZOS-API Sample Code\Python for more examples like those shown in the article. 

Edit: I realized my initial response didn’t answer your over-arching question so - to answer your question more directly: the values in the constants library are a collection of any enumerated variable within the ZOS-API. In the syntax guide, we list the variable type of a command next to the command itself. The enumerated variables can be identified in the syntax guide as a link which directs to the enumeration information, as shown below:

 

 

They represent a collection of pre-defined values. Typically, this represents a drop-down list in the user-interface. So if you wanted to update the Rotation setting from the list above, you would click on the link Rotations and use the information listed under that enumeration from within the help system:

 

 

This is the information that the constants dictionary stores in the older PythonCOM connection and is all available in the ZOS-API Syntax Guide which can be opened within OpticStudio. 


Reply