[ZOS-API] Can I run Standalone and Interactive Extension at the same time?

  • 8 April 2020
  • 1 reply
  • 153 views

Userlevel 6
Badge +2
Are you having any problem with trying to run two different modes in a ZOS-API code?

Here is some tricks for you!!



First, if you exactly need to run two mode in a code, remember that you can only have one "IZOSAPI_Application" at a time. You will need to close the previous application in one mode in order to open it.  In below, we provided a sample code.

 

import os
from win32com.client.gencache import EnsureDispatch
from win32com.client import gencache
if __name__ == "__main__":
# Create Connection
gencache.EnsureModule('{EA433010-2BAC-43C4-857C-7AEAC4A8CCE0}', 0, 1, 0)
gencache.EnsureModule('{F66684D7-AAFE-4A62-9156-FF7A7853F764}', 0, 1, 0)
TheConnection = EnsureDispatch("ZOSAPI.ZOSAPI_Connection")
if TheConnection is None:
raise PythonStandaloneApplication.ConnectionException("Unable to intialize COM connection to ZOSAPI")
# Test for Extension
TheExtApplication = TheConnection.ConnectAsExtension(0)
if TheExtApplication is None:
raise Exception("Unable to acquire TheExtApplication")
if not TheExtApplication.IsValidLicenseForAPI:
raise Exception("License is not valid for ZOSAPI use")
TheExtSystem = TheExtApplication.PrimarySystem
if TheExtSystem is None:
raise Exception("Unable to acquire _TheIESystem")

# Do something in Interactive Extension

TheExtApplication.CloseApplication()
# Test for Standalone
TheStandApplication = TheConnection.CreateNewApplication()
if TheStandApplication is None:
raise PythonStandaloneApplication.InitializationException("Unable to acquire TheStandApplication")
if TheStandApplication.IsValidLicenseForAPI == False:
raise PythonStandaloneApplication.LicenseException("License is not valid for ZOSAPI use")
TheStandSystem = TheStandApplication.PrimarySystem
if TheStandSystem is None:
raise PythonStandaloneApplication.SystemNotPresentException("Unable to acquire _TheSASystem")
# Do something in Stand Alone





On the other hand, there is actually a potentially better solution depending on your purpose. That is, in ZOS-API, you are allowed to have multiple IOpticalSystem simultaneously. Just check the following methods!!



LoadNewSystem()

CreateNewSystem()

at IZOSAPI_Application



CopySystem()

at IOpticalSystem



Hope this is what you are looking for!

Thank you for reading!

1 reply

Userlevel 6
Badge +2
Thank you Michael!

Reply