Hi,
A long time ago I experienced the same problem. I am not entirely sure about the solution, but I think I removed the Zemax data directory and let OpticStudio reinstall the data directory. My hypothesis is that the data directory was created by a Zemax version of OpticStudio (like your hypothesis), and that the ZOSAPI_NetHelper.dll
somehow tries to connect to the non-existent Zemax version of OpticStudio. Reinstalling the data directory would then solve this, because it creates a ZOSAPI_NetHelper.dll
that works with Ansys OpticStudio.
If you're curious, you can also explicitly specify the path to the ZOSAPI_NetHelper.dll. The OpticStudio installation directory always contains a ZOSAPI_NetHelper.dll
(e.g. C:\Program Files\Ansys Zemax OpticStudio 2024 R1.03\ZOSAPI_NetHelper.dll
) that I expect to work with that specific version of OpticStudio. Can your code find OpticStudio when using that ZOSAPI_NetHelper.dll
instead of the automatically detected ZOSAPI_NetHelper.dll
?
By the way, nice that you mention ZOSPy allows to specify the path directly! Note that this option was added in ZOSPy 1.2.0 (released in January 2024), so it does not work with older versions.
Hey Joachim,
The ZOS-API actually uses 2 different Windows Registry locations to connect to OpticStudio. The Windows Registry location for identifying the location of the ZOSAPI_NetHelper.dll
is extremely trivial. The location is simply looking for the currently logged in user > Software > Zemax > ZemaxRoot. This then points to the NetHelper.dll which is located at the C:\Users\UserName\Documents\Zemax folder. Once the NetHelper is loaded, this DLL searches in 4 different locations for the actual OpticStudio executable:
- The user override directory
- The current folder that the NetHelper DLL is located in
- The parent folder that the NetHelper DLL is located in
- The GUID that OpticStudio is registered under (this is the key search in Windows Registry)
So basically #2 and #3 don’t do anything by default (these work if you use Corné’s method in paragraph 2 of linking to the NetHelper in the Program Files directory) and only #1 and #4 can successfully locate the OpticStudio.exe file location using the Python template. The GUID entry in #4 can sometimes become corrupt when installing/uninstalling different versions of the software. To fix this, you can call the .NET Framework’s regasm.exe and re-register the ZOSAPI.dll, ZOSAPI_Interfaces.dll, ZOSAPI.tlb and ZOSAPII.tlb. I know the Support team was testing out a tool to help re-register that the Development team created, but I’m not sure if it was ever fully tested and implemented. You might want to open a ticket and see if this tool was ever finished and released.
The easiest way to fix this Windows Registry issue is to simply reinstall the latest version of Ansys OpticStudio you want to use and this issue should be fixed (the installer calls regasm.exe and properly modifies the Windows Registry).
Just an additional historic note for compiled ZOS-API programs (doesn’t apply to Python), in 2022 OpticStudio allowed both 32-bit and 64-bit compiled programs to connect to OpticStudio by having a 32-bit Windows Registry entry point and also having a 64-bit Windows Registry point (OpticStudio itself has always been 64-bit but 32-bit programs could connect to it). In January of 2023, Ansys OpticStudio removed the 32-bit entry point so any 32-bit compiled programs being used with a fresh version of Windows which never had the old OpticStudio installed would not work; if you previously had a 2022 OpticStudio installed (so the installer created a 32-bit entry point) and then you tried to use a 32-bit program with a 2023 OpticStudio, you were fine. But if you have a brand new computer and the first version of OpticStudio you had ever installed was 2023, then these programs would not work. I’m not sure if Zemax has fixed the sample User Analysis and User Extensions (I doubt it because their C# template still has Prefer 32-bit toggled) they ship with, but that’s the issue that a lot of users had with the sample compiled programs.
Hi,
A long time ago I experienced the same problem. I am not entirely sure about the solution, but I think I removed the Zemax data directory and let OpticStudio reinstall the data directory. My hypothesis is that the data directory was created by a Zemax version of OpticStudio (like your hypothesis), and that the ZOSAPI_NetHelper.dll
somehow tries to connect to the non-existent Zemax version of OpticStudio. Reinstalling the data directory would then solve this, because it creates a ZOSAPI_NetHelper.dll
that works with Ansys OpticStudio.
If you're curious, you can also explicitly specify the path to the ZOSAPI_NetHelper.dll. The OpticStudio installation directory always contains a ZOSAPI_NetHelper.dll
(e.g. C:\Program Files\Ansys Zemax OpticStudio 2024 R1.03\ZOSAPI_NetHelper.dll
) that I expect to work with that specific version of OpticStudio. Can your code find OpticStudio when using that ZOSAPI_NetHelper.dll
instead of the automatically detected ZOSAPI_NetHelper.dll
?
By the way, nice that you mention ZOSPy allows to specify the path directly! Note that this option was added in ZOSPy 1.2.0 (released in January 2024), so it does not work with older versions.
Some old dll-files seem to be the issue. I just deleted the personal zemax folder from Document folder (after saving my project files). After restart, it says the files are missing and need to be copied again. Unfortunately, after that it takes some time and still a few files are missing. So I went to the menu to add/remove programs, and I checked to repair my current zemax setup. After that I started up again, it said again some files are missing and this time it copied all the data over. I copied back my project files, and now the default script is working.
The DLL files from C:\Program Files\.. and C:\users\…. had a different size, so they were different.
After an Update to Ansys OpticsStudio 2024 R2.01 it is broken again. This time copying the dll did not help.
For the example code for the PythonZOSConnection, I just put manually the path of the setup:
# uncomment the following line to use a specific instance of the ZOS-API assemblies
pathToInstall = r'C:\Program Files\Ansys Zemax OpticStudio 2024 R2.01'
and for the zospy library, you can also use the folder manually:
import zospy as zp
pathToInstall = r'C:\Program Files\Ansys Zemax OpticStudio 2024 R2.01'
zos = zp.ZOS(opticstudio_directory=pathToInstall)
oss = zos.connect("extension")