How how to run specific verion of OpticStudio in ZOS-API

  • 4 June 2021
  • 2 replies
  • 148 views

Userlevel 3
Badge

If I have several versions of ZOS installed on PC how can I specify in ZOS-API tool (Python) what version should be used?


2 replies

Userlevel 5
Badge +2

Hi Andrey,


Thanks for your post here on the forums!


If you check the sample codes provided with OpticStudio in the ZOS-API Syntax help, or the boilerplate code, you can see that the python codes start as the following:



class PythonStandaloneApplication1(object):
    class LicenseException(Exception):
        pass
    class ConnectionException(Exception):
        pass
    class InitializationException(Exception):
        pass
    class SystemNotPresentException(Exception):
        pass
    def __init__(self, path=None):
        # determine location of ZOSAPI_NetHelper.dll & add as reference
        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)
        clr.AddReference(NetHelper)
        import ZOSAPI_NetHelper
        
        # Find the installed version of OpticStudio
        #if len(path) == 0:
        if path is None:
            isInitialized = ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize()
        else:
            # Note -- uncomment the following line to use a custom initialization path
            isInitialized = ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize(path)

        
        # determine the ZOS root directory
        if isInitialized:
            dir = ZOSAPI_NetHelper.ZOSAPI_Initializer.GetZemaxDirectory()
        else:
            raise PythonStandaloneApplication1.InitializationException('Unable to locate Zemax OpticStudio.  Try using a hard-coded path.')

In the above section, there are two ways for the initialization, one without any given path, in which case the default path is used, and a second one with a given path, in which case the API code searches for OpticStudio at that specifc given location. 


If you would like to run a specific version of OpticStudio, you can customize the initialization with the path where the specific version of OpticStudio that you would like to run is installed.


I hope this helps, but if you have any further questions, please let us know and we will be happy to help!


Best,

Csilla

Userlevel 3
Badge

Hi Csilla,


 


Thank you for your answer!

Reply