Hi.
I am using the ZOS-API for Python and try to switch to the new recommended method of using PythonNET instead of the COM interface. To do so, I created a new Python template using 'Programming>Python>Interactive Extension' (same problem occurs with 'Standalone Application'). Running this template fails when trying to add the NetHelper DLL:
import clr, os, winreg
from itertools import islice
# determine the Zemax working directory
aKey = winreg.OpenKey(winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER), r'Software\Zemax', 0, winreg.KEY_READ)
zemaxData = winreg.QueryValueEx(aKey, 'ZemaxRoot')
NetHelper = os.path.join(os.sep, zemaxData[0], r'ZOS-API\Libraries\ZOSAPI_NetHelper.dll')
winreg.CloseKey(aKey)
# add the NetHelper DLL for locating the OpticStudio install folder
clr.AddReference(NetHelper)
import ZOSAPI_NetHelper
---------------------------------------------------------------------------
FileNotFoundException Traceback (most recent call last)
in
9
10 # add the NetHelper DLL for locating the OpticStudio install folder
---> 11 clr.AddReference(NetHelper)
12 import ZOSAPI_NetHelper
FileNotFoundException: Unable to find assembly 'Z:\...\Zemax\ZOS-API\Libraries\ZOSAPI_NetHelper.dll'.
at Python.Runtime.CLRModule.AddReference(String name)
I checked, and the dll is present at the correct location. I know that the NetHelper is just used to find the install folder of Zemax and that I can circumvent this problem by specifying the Zemax folder location directly:
import clr, os
zemaxDir = 'C:\Program Files\Zemax OpticStudio 20.2'
# load the ZOS-API assemblies
clr.AddReference(os.path.join(os.sep, zemaxDir, r'ZOSAPI.dll'))
clr.AddReference(os.path.join(os.sep, zemaxDir, r'ZOSAPI_Interfaces.dll'))
clr.setPreload(True)
import ZOSAPI
This works fine and I can connect to the ZOS-API and interact with OpticStudio. However, I would prefer the solution with the NetHelper since this way my code remains the same when installing a new version of OpticStudio or when changing the computer.
Do you know why the NetHelper cannot be added and how to fix this?
Best,
Erik