Skip to main content
Solved

ZOS API: opening a ZAR file

  • January 16, 2021
  • 3 replies
  • 310 views

c​hris

I'm using the ZOS API to work with ZAR files our engineers produce. We're using ZAR files since there are CAD files associated with the ZMX file. I want to open a ZAR file. There aren't any examples of how to do this, and `TheSystem.Tools.OpenRestoreZAR` isn't well documented; for example, `get_ArchiveFile` isn't in the docs.



Here is my code so far:



zos = PythonStandaloneApplication()
zos_api = zos.ZOSAPI
zos_system = zos.TheSystem
zos_system.MakeNonSequential()
zos_system.SystemData.MaterialCatalogs.AddCatalog('SCHOTT')
non_sequential_component_editor = zos_system.NCE
zar_path = os.path.join('..', 'data', config['filename'])
if not os.path.exists(zar_path):
print(f'ZAR file does not exist at {zar_path}.')
zar_restorer = zos_system.Tools.OpenRestoreZAR()
status_code = zar_restorer.SetFileName(zar_path)
print(status_code)

`SetFileName` doesn't work even if I know there is a ZAR file at that location. Where do I go from here? I want to open the ZAR file and run a ray trace with `zos_system.Tools.OpenNSCRayTrace()`.


 

Best answer by Csilla Timar-Fulep

Hi Chris,


Thanks for posting here on the forums!


In order to open a ZAR file from the API, you need to to run the Restore Archive tool. You may find more information about the member functions and properties of the ZOSAPI.Tools.General.IRestoreArchive Interface Reference in the ZOS-API Syntax Help:



After opening the tool and adjusting its settings, you will need to run it. Please find the python code below:



zar_restorer = TheSystem.Tools.OpenRestoreZAR()
status_code = zar_restorer.SetFileName(ZARfilePath)
zar_restorer.RunAndWaitForCompletion()
zar_restorer.Close()

When running the code you will need to provide the full path name, including the file name and its extension.


I hope this helps!

If you have further questions, please let us know and we will be happy to help!


Best,


Csilla

View original
Did this topic help you find an answer to your question?

3 replies

c​hris
  • Author
  • Infrared
  • 12 replies
  • January 16, 2021

For now, I can ask them to send me a zip file. I'd prefer to use ZAR so that it's easier for them.


c​hris
  • Author
  • Infrared
  • 12 replies
  • January 16, 2021

Even though Python can recognize that a file exists there, the ZOS API doesn't work if you use relative paths. This problem also exists for opening ZMX files. Changing it to an absolute path worked. :(



Help is welcome if anyone has an example of working with a ZAR file.


Csilla Timar-Fulep
Zemax Staff
Forum|alt.badge.img+2

Hi Chris,


Thanks for posting here on the forums!


In order to open a ZAR file from the API, you need to to run the Restore Archive tool. You may find more information about the member functions and properties of the ZOSAPI.Tools.General.IRestoreArchive Interface Reference in the ZOS-API Syntax Help:



After opening the tool and adjusting its settings, you will need to run it. Please find the python code below:



zar_restorer = TheSystem.Tools.OpenRestoreZAR()
status_code = zar_restorer.SetFileName(ZARfilePath)
zar_restorer.RunAndWaitForCompletion()
zar_restorer.Close()

When running the code you will need to provide the full path name, including the file name and its extension.


I hope this helps!

If you have further questions, please let us know and we will be happy to help!


Best,


Csilla


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings