zemax的编程功能简介
An application programming interface (ZOS-API) has been developed for OpticStudio that enables connections to, and customization of, the application using the latest software technology. While ZOS-API relies on a COM interface, it is rooted in .NET libraries, and as such programming with the API can be done using either C++ (COM) or C# (.NET) – depending on the user’s comfort with either language.
可以直接使用ZPL宏(Zemax Programming Language)在ZEMAX内编程,也可以使用提供的ZOS-API在外部编程然后连接进入ZEMAX,其有如下四种方式:
- 独立应用程序模式Standalone Mode
- 自定义扩展模式User Extensions Mode
- 自定义操作数模式User Operands Mode
- 自定义分析模式User Analysis Mode
支持的语言有:ZPL,C#,C++,MATLAB,Python。
ZPL快速使用
ZPL与BASIC语言类似,表达式之前不需要声明变量.表达式结尾不需要 特殊终止符(如 C 语言中的“;”)。因此,每条 ZPL 命令必须独占一行。ZPL内置示例文件:
编程->新建宏
x=5
PRINT "Hello ZPL编程,x=",x
然后另存为到~/Zemax/Macros/hello_zpl.ZPL,编程->编辑/执行选择刚才的文件执行.
ZOS-API快速使用
本文主要关注ZOS-API与C++的协作
连接ZOS-API
有两种不同方法连接到ZOS-API
- 用户的应用程序是“独立”的,并且将在执行期间启动ZemaxOpticStudio。
- Zemax OpticStudio 已经在运行,并且将“调用”用户的(“固有”)应用程序。
固有应用程序(ZOS Inherent(ZOS uses your Application))
- 自定义扩展 User Extension
- 自定义分析 User Analyses
- 自定义操作数 User Operand
这些均被视为“固有”程序,表示 ZOS 使用已编译的应用程序。
配置Visual Studio Code编译C++并连接到ZOS-API
正确的操作是, ZOSAPI.dll 和 ZOSAPI_Interfaces.dll 必须保留在 OpticStudio 安装目录中。另一方面, ZOSAPI_NetHelper.dll 应始终位于运行应用程序的目录中。这意味着,如果您在开发自定义 分析、自定义操作数或自定义扩展程序,ZOSAP I_NetHelper.dll 应该与您的插件一起复制到 合适的位置。
Visual Studio Code安装C/C++(Microsoft),C/C++ Compile Run(danielpinto8zz6),Code Runner(Jun Han)三个插件
文件->首选项->设置搜索runInTerminal,勾选C-cpp-compile-run:Run-in-external-terminal和Code-runner:Run-In Terminal
安装MinGW-w64,看到
即安装成功,然后重启VS Code
新建文件hello.cpp
#include <iostream>
int main(void){
std::cout<<"hello world";
}
信任此工作区
右键,点击Run Code