Skip to main content
Solved

How i can connect to microsoft excel with zemax?


How i can  connect to microsoft excel with zemax?

Best answer by Csilla Timar-Fulep

Hello Sheng-BO,

Thanks for your question here!
 

You can connect to Excel throught ZOS-API. The communication between Excel and ZOS-API is easy once you have the references enabled in Visual Basic for Applications environment. To do so, open VBA (Alt+F11 from any Excel sheet), then click on Tools > References and finally scroll down to the bottom of the list and select ZOSAPI and ZOSAPI_Interfaces:



From here, you can create a new Module and create your subroutines.
There are a few things to note, please see them below:

  • You need to explicitly declare your variable types with the Dim keyword (at the beginning of your Sub)
  • For any method which is not assigned to a variable, you will need to treat it like a ZPL keyword where you don’t use the parenthesis to pass in the arguments 
  • There is INTELLISENSE
  • Inheritance: When a child class inherits from a parent class, you will need to have 2 variables defined to use the API tools, one for the child tool to set the specific properties and one for the parent tool to run & close the tool. 

If you have further questions, please let us know and we will be happy to help!

Best,

Csilla

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

4 replies

Csilla Timar-Fulep
Zemax Staff
Forum|alt.badge.img+2

Hello Sheng-BO,

Thanks for your question here!
 

You can connect to Excel throught ZOS-API. The communication between Excel and ZOS-API is easy once you have the references enabled in Visual Basic for Applications environment. To do so, open VBA (Alt+F11 from any Excel sheet), then click on Tools > References and finally scroll down to the bottom of the list and select ZOSAPI and ZOSAPI_Interfaces:



From here, you can create a new Module and create your subroutines.
There are a few things to note, please see them below:

  • You need to explicitly declare your variable types with the Dim keyword (at the beginning of your Sub)
  • For any method which is not assigned to a variable, you will need to treat it like a ZPL keyword where you don’t use the parenthesis to pass in the arguments 
  • There is INTELLISENSE
  • Inheritance: When a child class inherits from a parent class, you will need to have 2 variables defined to use the API tools, one for the child tool to set the specific properties and one for the parent tool to run & close the tool. 

If you have further questions, please let us know and we will be happy to help!

Best,

Csilla


THANK YOU


Hi Csilla,

Using Excel to communicate with Zemax is very interesting for me.

This because I'm familiar with VBA but not as much with the other languages.

Can you provide me with some examples of how VBA is used so that I can learn about the syntax details?

Hope you can help me.

The best regards

Pascal

 

 


Csilla Timar-Fulep
Zemax Staff
Forum|alt.badge.img+2

Hi Pascal,

Thanks for your follow-up question here.

For more info about how to use Excel specifically, I would recommend to check these knowledgebase articles and forum threads:
Required OpticStudio version and language for using ZOS-API · MyZemax
ZOS-API & Excel interactive extension example- retrieve incident angles on surfaces across pupil · MyZemax
The problem with microsoft excel Connect to ZEMAX · MyZemax

Regarding the API-specific commands, these are usually very similar across the programming languages. To learn more about the syntax, please take a look at the following ZOS-API learning path and these knowledgebase articles:
Getting Started with ZOS-API · MyZemax
Sample code for ZOS-API users · MyZemax
Navigating the ZOS-API Syntax Help document - Part 1 · MyZemax

Finally, I am attaching 2 sample codes written by my colleagues.

Best,
Csilla


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